PK КyЩL 11-WindowsFormsThreadingModel/PK vdB├y@╬╗ ╗ ( 11-WindowsFormsThreadingModel/App.configя╗┐
PK edB╒MЬ▐У У ( 11-WindowsFormsThreadingModel/AppForm.csя╗┐using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Threading;
namespace WindowsFormsThreadingModel {
public partial class AppForm : Form {
private AppForm parentForm = null;
public AppForm() {
InitializeComponent();
}
protected override void OnLoad(EventArgs e) {
base.OnLoad(e);
Text = Text + string.Format(": {0}, Parent: '{1}'", Thread.CurrentThread.ManagedThreadId, parentForm);
}
private void showInfoButton_Click(object sender, EventArgs e) {
MessageBox.Show(string.Format("ManagedThreadId: {0}", Thread.CurrentThread.ManagedThreadId));
}
private void addFormHereButton_Click(object sender, EventArgs e) {
var f = new AppForm();
f.parentForm = this;
f.Show();
}
private void addFormInThreadButton_Click(object sender, EventArgs e) {
var t = new Thread(() => {
var f = new AppForm();
f.parentForm = this;
Application.Run(f);
});
t.Start();
}
private void setLabelButton_Click(object sender, EventArgs e) {
label1.Text = DateTime.Now.ToLongTimeString();
}
private void setLabelInThreadButton_Click(object sender, EventArgs e) {
var t = new Thread(() => {
label1.Text = DateTime.Now.ToLongTimeString();
});
t.Start();
}
private void setLabelInParentButton_Click(object sender, EventArgs e) {
if (parentForm == null) {
MessageBox.Show("No parent form assigned.");
} else {
parentForm.label1.Text = DateTime.Now.ToLongTimeString();
}
}
private void setLabelViaInvokeButton_Click(object sender, EventArgs e) {
var t = new Thread(() => {
this.Invoke((Action) (
() => {
label1.Text = DateTime.Now.ToLongTimeString();
}
));
});
t.Start();
}
private void setParentLabelViaInvokeButton_Click(object sender, EventArgs e) {
if (parentForm == null) {
MessageBox.Show("No parent form assigned.");
} else {
if (parentForm.InvokeRequired) {
parentForm.Invoke((Action) (
() => {
parentForm.label1.Text = DateTime.Now.ToLongTimeString() + " via Invoke";
}
));
} else {
parentForm.label1.Text = DateTime.Now.ToLongTimeString() + " directly set";
}
}
}
}
}
PK ╝dB]Ф▌) ) 1 11-WindowsFormsThreadingModel/AppForm.Designer.csя╗┐namespace WindowsFormsThreadingModel {
partial class AppForm {
///
/// Required designer variable.
///
private System.ComponentModel.IContainer components = null;
///
/// Clean up any resources being used.
///
/// true if managed resources should be disposed; otherwise, false.
protected override void Dispose(bool disposing) {
if (disposing && (components != null)) {
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent() {
this.showInfoButton = new System.Windows.Forms.Button();
this.addFormHereButton = new System.Windows.Forms.Button();
this.addFormInThreadButton = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.setLabelButton = new System.Windows.Forms.Button();
this.setLabelInThreadButton = new System.Windows.Forms.Button();
this.setLabelInParentButton = new System.Windows.Forms.Button();
this.setLabelViaInvokeButton = new System.Windows.Forms.Button();
this.setParentLabelViaInvokeButton = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// showInfoButton
//
this.showInfoButton.Location = new System.Drawing.Point(143, 12);
this.showInfoButton.Name = "showInfoButton";
this.showInfoButton.Size = new System.Drawing.Size(75, 23);
this.showInfoButton.TabIndex = 0;
this.showInfoButton.Text = "Show info";
this.showInfoButton.UseVisualStyleBackColor = true;
this.showInfoButton.Click += new System.EventHandler(this.showInfoButton_Click);
//
// addFormHereButton
//
this.addFormHereButton.Location = new System.Drawing.Point(129, 41);
this.addFormHereButton.Name = "addFormHereButton";
this.addFormHereButton.Size = new System.Drawing.Size(106, 23);
this.addFormHereButton.TabIndex = 1;
this.addFormHereButton.Text = "Add form here";
this.addFormHereButton.UseVisualStyleBackColor = true;
this.addFormHereButton.Click += new System.EventHandler(this.addFormHereButton_Click);
//
// addFormInThreadButton
//
this.addFormInThreadButton.Location = new System.Drawing.Point(111, 311);
this.addFormInThreadButton.Name = "addFormInThreadButton";
this.addFormInThreadButton.Size = new System.Drawing.Size(147, 23);
this.addFormInThreadButton.TabIndex = 2;
this.addFormInThreadButton.Text = "Add form in new thread";
this.addFormInThreadButton.UseVisualStyleBackColor = true;
this.addFormInThreadButton.Click += new System.EventHandler(this.addFormInThreadButton_Click);
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(161, 131);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(35, 13);
this.label1.TabIndex = 3;
this.label1.Text = "label1";
//
// setLabelButton
//
this.setLabelButton.Location = new System.Drawing.Point(68, 161);
this.setLabelButton.Name = "setLabelButton";
this.setLabelButton.Size = new System.Drawing.Size(101, 23);
this.setLabelButton.TabIndex = 4;
this.setLabelButton.Text = "Set label here";
this.setLabelButton.UseVisualStyleBackColor = true;
this.setLabelButton.Click += new System.EventHandler(this.setLabelButton_Click);
//
// setLabelInThreadButton
//
this.setLabelInThreadButton.Location = new System.Drawing.Point(175, 161);
this.setLabelInThreadButton.Name = "setLabelInThreadButton";
this.setLabelInThreadButton.Size = new System.Drawing.Size(155, 23);
this.setLabelInThreadButton.TabIndex = 5;
this.setLabelInThreadButton.Text = "Set label in another thread";
this.setLabelInThreadButton.UseVisualStyleBackColor = true;
this.setLabelInThreadButton.Click += new System.EventHandler(this.setLabelInThreadButton_Click);
//
// setLabelInParentButton
//
this.setLabelInParentButton.Location = new System.Drawing.Point(111, 190);
this.setLabelInParentButton.Name = "setLabelInParentButton";
this.setLabelInParentButton.Size = new System.Drawing.Size(155, 23);
this.setLabelInParentButton.TabIndex = 6;
this.setLabelInParentButton.Text = "Set label of parent form";
this.setLabelInParentButton.UseVisualStyleBackColor = true;
this.setLabelInParentButton.Click += new System.EventHandler(this.setLabelInParentButton_Click);
//
// setLabelViaInvokeButton
//
this.setLabelViaInvokeButton.Location = new System.Drawing.Point(68, 219);
this.setLabelViaInvokeButton.Name = "setLabelViaInvokeButton";
this.setLabelViaInvokeButton.Size = new System.Drawing.Size(262, 23);
this.setLabelViaInvokeButton.TabIndex = 7;
this.setLabelViaInvokeButton.Text = "Set label in another thread via Invoke";
this.setLabelViaInvokeButton.UseVisualStyleBackColor = true;
this.setLabelViaInvokeButton.Click += new System.EventHandler(this.setLabelViaInvokeButton_Click);
//
// setParentLabelViaInvokeButton
//
this.setParentLabelViaInvokeButton.Location = new System.Drawing.Point(68, 248);
this.setParentLabelViaInvokeButton.Name = "setParentLabelViaInvokeButton";
this.setParentLabelViaInvokeButton.Size = new System.Drawing.Size(262, 23);
this.setParentLabelViaInvokeButton.TabIndex = 8;
this.setParentLabelViaInvokeButton.Text = "Set label of parent via Invoke";
this.setParentLabelViaInvokeButton.UseVisualStyleBackColor = true;
this.setParentLabelViaInvokeButton.Click += new System.EventHandler(this.setParentLabelViaInvokeButton_Click);
//
// AppForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(366, 346);
this.Controls.Add(this.setParentLabelViaInvokeButton);
this.Controls.Add(this.setLabelViaInvokeButton);
this.Controls.Add(this.setLabelInParentButton);
this.Controls.Add(this.setLabelInThreadButton);
this.Controls.Add(this.setLabelButton);
this.Controls.Add(this.label1);
this.Controls.Add(this.addFormInThreadButton);
this.Controls.Add(this.addFormHereButton);
this.Controls.Add(this.showInfoButton);
this.Name = "AppForm";
this.Text = "WinForms Threading Model";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Button showInfoButton;
private System.Windows.Forms.Button addFormHereButton;
private System.Windows.Forms.Button addFormInThreadButton;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Button setLabelButton;
private System.Windows.Forms.Button setLabelInThreadButton;
private System.Windows.Forms.Button setLabelInParentButton;
private System.Windows.Forms.Button setLabelViaInvokeButton;
private System.Windows.Forms.Button setParentLabelViaInvokeButton;
}
}
PK ╝dB╛|EI╣ ╣ * 11-WindowsFormsThreadingModel/AppForm.resxя╗┐
text/microsoft-resx
2.0
System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
PK ЭdB╤и╙ ╙ ( 11-WindowsFormsThreadingModel/Program.csя╗┐using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsThreadingModel {
static class Program {
///
/// The main entry point for the application.
///
[STAThread]
static void Main() {
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new AppForm());
}
}
}
PK КyЩL ) 11-WindowsFormsThreadingModel/Properties/PK vdBRW╢$╕ ╕ 8 11-WindowsFormsThreadingModel/Properties/AssemblyInfo.csя╗┐using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("WindowsFormsThreadingModel")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("WindowsFormsThreadingModel")]
[assembly: AssemblyCopyright("Copyright ┬й 2013")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("6bca93db-1266-4747-b3af-5a1da4eb89a6")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
PK vdBU╡l┐╔ ╔ > 11-WindowsFormsThreadingModel/Properties/Resources.Designer.csя╗┐//------------------------------------------------------------------------------
//
// This code was generated by a tool.
// Runtime Version:4.0.30319.18034
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
//
//------------------------------------------------------------------------------
namespace WindowsFormsThreadingModel.Properties {
///
/// A strongly-typed resource class, for looking up localized strings, etc.
///
// This class was auto-generated by the StronglyTypedResourceBuilder
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources() {
}
///
/// Returns the cached ResourceManager instance used by this class.
///
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if ((resourceMan == null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("WindowsFormsThreadingModel.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
///
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
///
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
}
}
PK vdBФZtvь ь 7 11-WindowsFormsThreadingModel/Properties/Resources.resxя╗┐
text/microsoft-resx
2.0
System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
PK vdBф┘ = 11-WindowsFormsThreadingModel/Properties/Settings.Designer.csя╗┐//------------------------------------------------------------------------------
//
// This code was generated by a tool.
// Runtime Version:4.0.30319.18034
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
//
//------------------------------------------------------------------------------
namespace WindowsFormsThreadingModel.Properties {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings) (global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
public static Settings Default {
get {
return defaultInstance;
}
}
}
}
PK vdB`Ч╪∙ ∙ : 11-WindowsFormsThreadingModel/Properties/Settings.settingsя╗┐
PK №dB[Ы? ? 11-WindowsFormsThreadingModel/WindowsFormsThreadingModel.csprojя╗┐
Debug
AnyCPU
{A9ADBEC3-A6A0-4D3B-A2A8-FFCC7CB96BD6}
WinExe
Properties
WindowsFormsThreadingModel
WindowsFormsThreadingModel
v4.5
512
AnyCPU
true
full
false
bin\Debug\
DEBUG;TRACE
prompt
4
AnyCPU
pdbonly
true
bin\Release\
TRACE
prompt
4
Form
AppForm.cs
AppForm.cs
ResXFileCodeGenerator
Resources.Designer.cs
Designer
True
Resources.resx
SettingsSingleFileGenerator
Settings.Designer.cs
True
Settings.settings
True
PK wdBАTPн н <