Click here to Skip to main content
15,896,371 members
Articles / Desktop Programming / MFC

The Practical Guide to Multithreading - Part 1

Rate me:
Please Sign up or sign in to vote.
4.89/5 (123 votes)
6 Apr 2010CPOL17 min read 304.7K   10.4K   453  
Learn from this guide how and when - as well as when not - to use multithreading.
namespace Multithreading_Guide_1
{
    partial class frmExample1
    {
        /// <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.label1 = new System.Windows.Forms.Label();
            this.label2 = new System.Windows.Forms.Label();
            this.txtStart = new System.Windows.Forms.TextBox();
            this.txtEnd = new System.Windows.Forms.TextBox();
            this.btnProcess = new System.Windows.Forms.Button();
            this.prgProcess = new System.Windows.Forms.ProgressBar();
            this.lblStatus = new System.Windows.Forms.Label();
            this.btnStartThreaded = new System.Windows.Forms.Button();
            this.SuspendLayout();
            // 
            // label1
            // 
            this.label1.AutoSize = true;
            this.label1.Location = new System.Drawing.Point(13, 31);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(32, 13);
            this.label1.TabIndex = 0;
            this.label1.Text = "Start:";
            // 
            // label2
            // 
            this.label2.AutoSize = true;
            this.label2.Location = new System.Drawing.Point(196, 31);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(29, 13);
            this.label2.TabIndex = 0;
            this.label2.Text = "End:";
            // 
            // txtStart
            // 
            this.txtStart.Location = new System.Drawing.Point(53, 31);
            this.txtStart.MaxLength = 15;
            this.txtStart.Name = "txtStart";
            this.txtStart.Size = new System.Drawing.Size(83, 20);
            this.txtStart.TabIndex = 1;
            this.txtStart.Text = "1";
            // 
            // txtEnd
            // 
            this.txtEnd.Location = new System.Drawing.Point(234, 31);
            this.txtEnd.Name = "txtEnd";
            this.txtEnd.Size = new System.Drawing.Size(83, 20);
            this.txtEnd.TabIndex = 1;
            this.txtEnd.Text = "10000";
            // 
            // btnProcess
            // 
            this.btnProcess.Location = new System.Drawing.Point(323, 24);
            this.btnProcess.Name = "btnProcess";
            this.btnProcess.Size = new System.Drawing.Size(157, 27);
            this.btnProcess.TabIndex = 2;
            this.btnProcess.Text = "Start Processing (no Thread)";
            this.btnProcess.UseVisualStyleBackColor = true;
            this.btnProcess.Click += new System.EventHandler(this.btnProcess_Click);
            // 
            // prgProcess
            // 
            this.prgProcess.Location = new System.Drawing.Point(16, 84);
            this.prgProcess.Name = "prgProcess";
            this.prgProcess.Size = new System.Drawing.Size(208, 14);
            this.prgProcess.TabIndex = 3;
            // 
            // lblStatus
            // 
            this.lblStatus.AutoSize = true;
            this.lblStatus.Location = new System.Drawing.Point(13, 101);
            this.lblStatus.MinimumSize = new System.Drawing.Size(200, 0);
            this.lblStatus.Name = "lblStatus";
            this.lblStatus.Size = new System.Drawing.Size(200, 13);
            this.lblStatus.TabIndex = 4;
            // 
            // btnStartThreaded
            // 
            this.btnStartThreaded.Location = new System.Drawing.Point(323, 57);
            this.btnStartThreaded.Name = "btnStartThreaded";
            this.btnStartThreaded.Size = new System.Drawing.Size(157, 27);
            this.btnStartThreaded.TabIndex = 2;
            this.btnStartThreaded.Text = "Start Processing (Threaded)";
            this.btnStartThreaded.UseVisualStyleBackColor = true;
            this.btnStartThreaded.Click += new System.EventHandler(this.btnStartThreaded_Click);
            // 
            // frmExample1
            // 
            this.AcceptButton = this.btnProcess;
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(483, 147);
            this.Controls.Add(this.lblStatus);
            this.Controls.Add(this.prgProcess);
            this.Controls.Add(this.btnStartThreaded);
            this.Controls.Add(this.btnProcess);
            this.Controls.Add(this.txtEnd);
            this.Controls.Add(this.txtStart);
            this.Controls.Add(this.label2);
            this.Controls.Add(this.label1);
            this.MaximizeBox = false;
            this.Name = "frmExample1";
            this.ShowIcon = false;
            this.Text = "Example 1";
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        #endregion

        private System.Windows.Forms.Label label1;
        private System.Windows.Forms.Label label2;
        private System.Windows.Forms.TextBox txtStart;
        private System.Windows.Forms.TextBox txtEnd;
        private System.Windows.Forms.Button btnProcess;
        private System.Windows.Forms.ProgressBar prgProcess;
        private System.Windows.Forms.Label lblStatus;
        private System.Windows.Forms.Button btnStartThreaded;

    }
}

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)
India India
Started programming with GwBasic back in 1996 (Those lovely days!). Found the hidden talent!

Touched COBOL and Quick Basic for a while.

Finally learned C and C++ entirely on my own, and fell in love with C++, still in love! Began with Turbo C 2.0/3.0, then to VC6 for 4 years! Finally on VC2008/2010.

I enjoy programming, mostly the system programming, but the UI is always on top of MFC! Quite experienced on other environments and platforms, but I prefer Visual C++. Zeal to learn, and to share!

Comments and Discussions