Click here to Skip to main content
15,884,298 members
Articles / Programming Languages / C#

Multithreading, Delegates, and Custom Events

Rate me:
Please Sign up or sign in to vote.
4.95/5 (74 votes)
17 Mar 2010CPOL12 min read 189.7K   3.3K   310  
Tie it all together and not lose your mind in the process
namespace MultiThreadDelegate
{
	partial class Form1
	{
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.IContainer components = null;

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
		protected override void Dispose(bool disposing)
		{
			if (disposing && (components != null))
			{
				components.Dispose();
			}
			base.Dispose(disposing);
		}

		#region Windows Form Designer generated code

		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.trackbarConcurrent = new System.Windows.Forms.TrackBar();
			this.label1 = new System.Windows.Forms.Label();
			this.textboxProcessCount = new System.Windows.Forms.TextBox();
			this.groupBox1 = new System.Windows.Forms.GroupBox();
			this.label2 = new System.Windows.Forms.Label();
			this.panel1 = new System.Windows.Forms.Panel();
			this.label18 = new System.Windows.Forms.Label();
			this.label17 = new System.Windows.Forms.Label();
			this.label16 = new System.Windows.Forms.Label();
			this.label15 = new System.Windows.Forms.Label();
			this.label14 = new System.Windows.Forms.Label();
			this.label13 = new System.Windows.Forms.Label();
			this.label12 = new System.Windows.Forms.Label();
			this.label11 = new System.Windows.Forms.Label();
			this.label10 = new System.Windows.Forms.Label();
			this.label9 = new System.Windows.Forms.Label();
			this.label8 = new System.Windows.Forms.Label();
			this.groupBox2 = new System.Windows.Forms.GroupBox();
			this.progressStep3 = new System.Windows.Forms.ProgressBar();
			this.progressStep2 = new System.Windows.Forms.ProgressBar();
			this.progressStep1 = new System.Windows.Forms.ProgressBar();
			this.label7 = new System.Windows.Forms.Label();
			this.listboxComplete = new System.Windows.Forms.ListBox();
			this.label6 = new System.Windows.Forms.Label();
			this.listboxStep3 = new System.Windows.Forms.ListBox();
			this.label5 = new System.Windows.Forms.Label();
			this.listboxStep2 = new System.Windows.Forms.ListBox();
			this.label4 = new System.Windows.Forms.Label();
			this.listboxStep1 = new System.Windows.Forms.ListBox();
			this.label3 = new System.Windows.Forms.Label();
			this.listboxQueued = new System.Windows.Forms.ListBox();
			this.buttonStart = new System.Windows.Forms.Button();
			this.buttonLoadQueue = new System.Windows.Forms.Button();
			this.buttonStop = new System.Windows.Forms.Button();
			this.buttonDone = new System.Windows.Forms.Button();
			this.buttonClear = new System.Windows.Forms.Button();
			((System.ComponentModel.ISupportInitialize)(this.trackbarConcurrent)).BeginInit();
			this.groupBox1.SuspendLayout();
			this.panel1.SuspendLayout();
			this.groupBox2.SuspendLayout();
			this.SuspendLayout();
			// 
			// trackbarConcurrent
			// 
			this.trackbarConcurrent.Location = new System.Drawing.Point(2, 2);
			this.trackbarConcurrent.Maximum = 100;
			this.trackbarConcurrent.Minimum = 1;
			this.trackbarConcurrent.Name = "trackbarConcurrent";
			this.trackbarConcurrent.Size = new System.Drawing.Size(823, 45);
			this.trackbarConcurrent.TabIndex = 0;
			this.trackbarConcurrent.Value = 10;
			// 
			// label1
			// 
			this.label1.AutoSize = true;
			this.label1.Location = new System.Drawing.Point(11, 26);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(173, 13);
			this.label1.TabIndex = 1;
			this.label1.Text = "Queue this many processes (1-255)";
			// 
			// textboxProcessCount
			// 
			this.textboxProcessCount.Location = new System.Drawing.Point(188, 22);
			this.textboxProcessCount.MaxLength = 3;
			this.textboxProcessCount.Name = "textboxProcessCount";
			this.textboxProcessCount.Size = new System.Drawing.Size(35, 20);
			this.textboxProcessCount.TabIndex = 2;
			this.textboxProcessCount.TextChanged += new System.EventHandler(this.textboxProcessCount_TextChanged);
			// 
			// groupBox1
			// 
			this.groupBox1.Controls.Add(this.label2);
			this.groupBox1.Controls.Add(this.panel1);
			this.groupBox1.Controls.Add(this.label1);
			this.groupBox1.Controls.Add(this.textboxProcessCount);
			this.groupBox1.Location = new System.Drawing.Point(7, 4);
			this.groupBox1.Name = "groupBox1";
			this.groupBox1.Size = new System.Drawing.Size(935, 129);
			this.groupBox1.TabIndex = 3;
			this.groupBox1.TabStop = false;
			this.groupBox1.Text = "Process Control";
			// 
			// label2
			// 
			this.label2.AutoSize = true;
			this.label2.Location = new System.Drawing.Point(11, 48);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(101, 13);
			this.label2.TabIndex = 5;
			this.label2.Text = "Concurrent Threads";
			// 
			// panel1
			// 
			this.panel1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
			this.panel1.Controls.Add(this.label18);
			this.panel1.Controls.Add(this.label17);
			this.panel1.Controls.Add(this.label16);
			this.panel1.Controls.Add(this.label15);
			this.panel1.Controls.Add(this.label14);
			this.panel1.Controls.Add(this.label13);
			this.panel1.Controls.Add(this.label12);
			this.panel1.Controls.Add(this.label11);
			this.panel1.Controls.Add(this.label10);
			this.panel1.Controls.Add(this.label9);
			this.panel1.Controls.Add(this.label8);
			this.panel1.Controls.Add(this.trackbarConcurrent);
			this.panel1.Location = new System.Drawing.Point(11, 64);
			this.panel1.Name = "panel1";
			this.panel1.Size = new System.Drawing.Size(831, 54);
			this.panel1.TabIndex = 4;
			// 
			// label18
			// 
			this.label18.AutoSize = true;
			this.label18.Location = new System.Drawing.Point(799, 33);
			this.label18.Name = "label18";
			this.label18.Size = new System.Drawing.Size(25, 13);
			this.label18.TabIndex = 11;
			this.label18.Text = "100";
			// 
			// label17
			// 
			this.label17.AutoSize = true;
			this.label17.Location = new System.Drawing.Point(723, 33);
			this.label17.Name = "label17";
			this.label17.Size = new System.Drawing.Size(19, 13);
			this.label17.TabIndex = 10;
			this.label17.Text = "90";
			// 
			// label16
			// 
			this.label16.AutoSize = true;
			this.label16.Location = new System.Drawing.Point(641, 33);
			this.label16.Name = "label16";
			this.label16.Size = new System.Drawing.Size(19, 13);
			this.label16.TabIndex = 9;
			this.label16.Text = "80";
			// 
			// label15
			// 
			this.label15.AutoSize = true;
			this.label15.Location = new System.Drawing.Point(561, 33);
			this.label15.Name = "label15";
			this.label15.Size = new System.Drawing.Size(19, 13);
			this.label15.TabIndex = 8;
			this.label15.Text = "70";
			// 
			// label14
			// 
			this.label14.AutoSize = true;
			this.label14.Location = new System.Drawing.Point(481, 33);
			this.label14.Name = "label14";
			this.label14.Size = new System.Drawing.Size(19, 13);
			this.label14.TabIndex = 7;
			this.label14.Text = "60";
			// 
			// label13
			// 
			this.label13.AutoSize = true;
			this.label13.Location = new System.Drawing.Point(400, 33);
			this.label13.Name = "label13";
			this.label13.Size = new System.Drawing.Size(19, 13);
			this.label13.TabIndex = 6;
			this.label13.Text = "50";
			// 
			// label12
			// 
			this.label12.AutoSize = true;
			this.label12.Location = new System.Drawing.Point(320, 33);
			this.label12.Name = "label12";
			this.label12.Size = new System.Drawing.Size(19, 13);
			this.label12.TabIndex = 5;
			this.label12.Text = "40";
			// 
			// label11
			// 
			this.label11.AutoSize = true;
			this.label11.Location = new System.Drawing.Point(240, 33);
			this.label11.Name = "label11";
			this.label11.Size = new System.Drawing.Size(19, 13);
			this.label11.TabIndex = 4;
			this.label11.Text = "30";
			// 
			// label10
			// 
			this.label10.AutoSize = true;
			this.label10.Location = new System.Drawing.Point(159, 33);
			this.label10.Name = "label10";
			this.label10.Size = new System.Drawing.Size(19, 13);
			this.label10.TabIndex = 3;
			this.label10.Text = "20";
			// 
			// label9
			// 
			this.label9.AutoSize = true;
			this.label9.Location = new System.Drawing.Point(78, 33);
			this.label9.Name = "label9";
			this.label9.Size = new System.Drawing.Size(19, 13);
			this.label9.TabIndex = 2;
			this.label9.Text = "10";
			// 
			// label8
			// 
			this.label8.AutoSize = true;
			this.label8.Location = new System.Drawing.Point(9, 33);
			this.label8.Name = "label8";
			this.label8.Size = new System.Drawing.Size(13, 13);
			this.label8.TabIndex = 1;
			this.label8.Text = "1";
			// 
			// groupBox2
			// 
			this.groupBox2.Controls.Add(this.progressStep3);
			this.groupBox2.Controls.Add(this.progressStep2);
			this.groupBox2.Controls.Add(this.progressStep1);
			this.groupBox2.Controls.Add(this.label7);
			this.groupBox2.Controls.Add(this.listboxComplete);
			this.groupBox2.Controls.Add(this.label6);
			this.groupBox2.Controls.Add(this.listboxStep3);
			this.groupBox2.Controls.Add(this.label5);
			this.groupBox2.Controls.Add(this.listboxStep2);
			this.groupBox2.Controls.Add(this.label4);
			this.groupBox2.Controls.Add(this.listboxStep1);
			this.groupBox2.Controls.Add(this.label3);
			this.groupBox2.Controls.Add(this.listboxQueued);
			this.groupBox2.Location = new System.Drawing.Point(7, 169);
			this.groupBox2.Name = "groupBox2";
			this.groupBox2.Size = new System.Drawing.Size(935, 406);
			this.groupBox2.TabIndex = 4;
			this.groupBox2.TabStop = false;
			this.groupBox2.Text = "Process Status";
			// 
			// progressStep3
			// 
			this.progressStep3.Location = new System.Drawing.Point(563, 373);
			this.progressStep3.Name = "progressStep3";
			this.progressStep3.Size = new System.Drawing.Size(177, 23);
			this.progressStep3.TabIndex = 11;
			// 
			// progressStep2
			// 
			this.progressStep2.Location = new System.Drawing.Point(379, 373);
			this.progressStep2.Name = "progressStep2";
			this.progressStep2.Size = new System.Drawing.Size(177, 23);
			this.progressStep2.TabIndex = 11;
			// 
			// progressStep1
			// 
			this.progressStep1.Location = new System.Drawing.Point(195, 373);
			this.progressStep1.Name = "progressStep1";
			this.progressStep1.Size = new System.Drawing.Size(177, 23);
			this.progressStep1.TabIndex = 10;
			// 
			// label7
			// 
			this.label7.AutoSize = true;
			this.label7.Location = new System.Drawing.Point(745, 15);
			this.label7.Margin = new System.Windows.Forms.Padding(0);
			this.label7.Name = "label7";
			this.label7.Size = new System.Drawing.Size(51, 13);
			this.label7.TabIndex = 9;
			this.label7.Text = "Complete";
			this.label7.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			// 
			// listboxComplete
			// 
			this.listboxComplete.FormattingEnabled = true;
			this.listboxComplete.IntegralHeight = false;
			this.listboxComplete.Location = new System.Drawing.Point(747, 30);
			this.listboxComplete.Name = "listboxComplete";
			this.listboxComplete.Size = new System.Drawing.Size(177, 366);
			this.listboxComplete.TabIndex = 8;
			// 
			// label6
			// 
			this.label6.AutoSize = true;
			this.label6.Location = new System.Drawing.Point(561, 15);
			this.label6.Margin = new System.Windows.Forms.Padding(0);
			this.label6.Name = "label6";
			this.label6.Size = new System.Drawing.Size(38, 13);
			this.label6.TabIndex = 7;
			this.label6.Text = "Step 3";
			this.label6.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			// 
			// listboxStep3
			// 
			this.listboxStep3.FormattingEnabled = true;
			this.listboxStep3.IntegralHeight = false;
			this.listboxStep3.Location = new System.Drawing.Point(563, 30);
			this.listboxStep3.Name = "listboxStep3";
			this.listboxStep3.Size = new System.Drawing.Size(177, 339);
			this.listboxStep3.TabIndex = 6;
			// 
			// label5
			// 
			this.label5.AutoSize = true;
			this.label5.Location = new System.Drawing.Point(377, 15);
			this.label5.Margin = new System.Windows.Forms.Padding(0);
			this.label5.Name = "label5";
			this.label5.Size = new System.Drawing.Size(38, 13);
			this.label5.TabIndex = 5;
			this.label5.Text = "Step 2";
			this.label5.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			// 
			// listboxStep2
			// 
			this.listboxStep2.FormattingEnabled = true;
			this.listboxStep2.IntegralHeight = false;
			this.listboxStep2.Location = new System.Drawing.Point(379, 30);
			this.listboxStep2.Name = "listboxStep2";
			this.listboxStep2.Size = new System.Drawing.Size(177, 339);
			this.listboxStep2.TabIndex = 4;
			// 
			// label4
			// 
			this.label4.AutoSize = true;
			this.label4.Location = new System.Drawing.Point(193, 15);
			this.label4.Margin = new System.Windows.Forms.Padding(0);
			this.label4.Name = "label4";
			this.label4.Size = new System.Drawing.Size(38, 13);
			this.label4.TabIndex = 3;
			this.label4.Text = "Step 1";
			this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			// 
			// listboxStep1
			// 
			this.listboxStep1.FormattingEnabled = true;
			this.listboxStep1.IntegralHeight = false;
			this.listboxStep1.Location = new System.Drawing.Point(195, 30);
			this.listboxStep1.Name = "listboxStep1";
			this.listboxStep1.Size = new System.Drawing.Size(177, 339);
			this.listboxStep1.TabIndex = 2;
			// 
			// label3
			// 
			this.label3.AutoSize = true;
			this.label3.Location = new System.Drawing.Point(9, 15);
			this.label3.Margin = new System.Windows.Forms.Padding(0);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(45, 13);
			this.label3.TabIndex = 1;
			this.label3.Text = "Queued";
			this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			// 
			// listboxQueued
			// 
			this.listboxQueued.FormattingEnabled = true;
			this.listboxQueued.IntegralHeight = false;
			this.listboxQueued.Location = new System.Drawing.Point(11, 30);
			this.listboxQueued.Name = "listboxQueued";
			this.listboxQueued.Size = new System.Drawing.Size(177, 366);
			this.listboxQueued.Sorted = true;
			this.listboxQueued.TabIndex = 0;
			// 
			// buttonStart
			// 
			this.buttonStart.Location = new System.Drawing.Point(436, 142);
			this.buttonStart.Name = "buttonStart";
			this.buttonStart.Size = new System.Drawing.Size(75, 23);
			this.buttonStart.TabIndex = 6;
			this.buttonStart.Text = "Start";
			this.buttonStart.UseVisualStyleBackColor = true;
			this.buttonStart.Click += new System.EventHandler(this.buttonStart_Click);
			// 
			// buttonLoadQueue
			// 
			this.buttonLoadQueue.Location = new System.Drawing.Point(352, 142);
			this.buttonLoadQueue.Name = "buttonLoadQueue";
			this.buttonLoadQueue.Size = new System.Drawing.Size(75, 23);
			this.buttonLoadQueue.TabIndex = 7;
			this.buttonLoadQueue.Text = "Load Queue";
			this.buttonLoadQueue.UseVisualStyleBackColor = true;
			this.buttonLoadQueue.Click += new System.EventHandler(this.buttonLoadQueue_Click);
			// 
			// buttonStop
			// 
			this.buttonStop.Location = new System.Drawing.Point(520, 142);
			this.buttonStop.Name = "buttonStop";
			this.buttonStop.Size = new System.Drawing.Size(75, 23);
			this.buttonStop.TabIndex = 8;
			this.buttonStop.Text = "Stop";
			this.buttonStop.UseVisualStyleBackColor = true;
			this.buttonStop.Click += new System.EventHandler(this.buttonStop_Click);
			// 
			// buttonDone
			// 
			this.buttonDone.Location = new System.Drawing.Point(437, 580);
			this.buttonDone.Name = "buttonDone";
			this.buttonDone.Size = new System.Drawing.Size(75, 23);
			this.buttonDone.TabIndex = 9;
			this.buttonDone.Text = "Done";
			this.buttonDone.UseVisualStyleBackColor = true;
			this.buttonDone.Click += new System.EventHandler(this.buttonDone_Click);
			// 
			// buttonClear
			// 
			this.buttonClear.Location = new System.Drawing.Point(267, 142);
			this.buttonClear.Name = "buttonClear";
			this.buttonClear.Size = new System.Drawing.Size(75, 23);
			this.buttonClear.TabIndex = 10;
			this.buttonClear.Text = "Clear";
			this.buttonClear.UseVisualStyleBackColor = true;
			this.buttonClear.Click += new System.EventHandler(this.buttonClear_Click);
			// 
			// Form1
			// 
			this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
			this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
			this.ClientSize = new System.Drawing.Size(949, 610);
			this.Controls.Add(this.buttonClear);
			this.Controls.Add(this.buttonDone);
			this.Controls.Add(this.buttonStop);
			this.Controls.Add(this.buttonLoadQueue);
			this.Controls.Add(this.buttonStart);
			this.Controls.Add(this.groupBox2);
			this.Controls.Add(this.groupBox1);
			this.Name = "Form1";
			this.Text = "Multithread Delegate Example";
			((System.ComponentModel.ISupportInitialize)(this.trackbarConcurrent)).EndInit();
			this.groupBox1.ResumeLayout(false);
			this.groupBox1.PerformLayout();
			this.panel1.ResumeLayout(false);
			this.panel1.PerformLayout();
			this.groupBox2.ResumeLayout(false);
			this.groupBox2.PerformLayout();
			this.ResumeLayout(false);

		}

		#endregion

		private System.Windows.Forms.TrackBar trackbarConcurrent;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.TextBox textboxProcessCount;
		private System.Windows.Forms.GroupBox groupBox1;
		private System.Windows.Forms.Panel panel1;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.GroupBox groupBox2;
		private System.Windows.Forms.ListBox listboxQueued;
		private System.Windows.Forms.ProgressBar progressStep2;
		private System.Windows.Forms.ProgressBar progressStep1;
		private System.Windows.Forms.Label label7;
		private System.Windows.Forms.ListBox listboxComplete;
		private System.Windows.Forms.Label label6;
		private System.Windows.Forms.ListBox listboxStep3;
		private System.Windows.Forms.Label label5;
		private System.Windows.Forms.ListBox listboxStep2;
		private System.Windows.Forms.Label label4;
		private System.Windows.Forms.ListBox listboxStep1;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.ProgressBar progressStep3;
		private System.Windows.Forms.Button buttonStart;
		private System.Windows.Forms.Button buttonLoadQueue;
		private System.Windows.Forms.Button buttonStop;
		private System.Windows.Forms.Button buttonDone;
		private System.Windows.Forms.Label label18;
		private System.Windows.Forms.Label label17;
		private System.Windows.Forms.Label label16;
		private System.Windows.Forms.Label label15;
		private System.Windows.Forms.Label label14;
		private System.Windows.Forms.Label label13;
		private System.Windows.Forms.Label label12;
		private System.Windows.Forms.Label label11;
		private System.Windows.Forms.Label label10;
		private System.Windows.Forms.Label label9;
		private System.Windows.Forms.Label label8;
		private System.Windows.Forms.Button buttonClear;
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) Paddedwall Software
United States United States
I've been paid as a programmer since 1982 with experience in Pascal, and C++ (both self-taught), and began writing Windows programs in 1991 using Visual C++ and MFC. In the 2nd half of 2007, I started writing C# Windows Forms and ASP.Net applications, and have since done WPF, Silverlight, WCF, web services, and Windows services.

My weakest point is that my moments of clarity are too brief to hold a meaningful conversation that requires more than 30 seconds to complete. Thankfully, grunts of agreement are all that is required to conduct most discussions without committing to any particular belief system.

Comments and Discussions