using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Threading;

namespace SimpleEx
{
	/// <summary>
	/// Form1 的摘要说明。
	/// </summary>
	public class MainApp : System.Windows.Forms.Form
	{
		private System.Windows.Forms.ListBox lbResult;
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;

		public MainApp()
		{
			InitializeComponent();
			DoSample();
		}

		/// <summary>
		/// 清理所有正在使用的资源。
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{
			this.lbResult = new System.Windows.Forms.ListBox();
			this.SuspendLayout();
			// 
			// lbResult
			// 
			this.lbResult.Dock = System.Windows.Forms.DockStyle.Fill;
			this.lbResult.Font = new System.Drawing.Font("Tahoma", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.lbResult.ItemHeight = 14;
			this.lbResult.Name = "lbResult";
			this.lbResult.Size = new System.Drawing.Size(292, 270);
			this.lbResult.TabIndex = 0;
			// 
			// MainApp
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(292, 273);
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.lbResult});
			this.Name = "MainApp";
			this.Text = "多线程的简单实例";
			this.ResumeLayout(false);

		}
		#endregion

		private void DoSample()
		{
			Thread thread1 = new Thread(new ThreadStart( Count));
			thread1.Name="线程一";
			Thread thread2 = new Thread(new ThreadStart( Count));
			thread2.Name="线程二";
			thread1.Start();
			thread2.Start();

		}

		private void Count()
		{
			for (int i=0;i<=5;i++)
			{
				lbResult.Items.Add(Thread.CurrentThread.Name + "数到" + i);
				Thread.Sleep(1000);
			}
			
		}

		

		/// <summary>
		/// 应用程序的主入口点。
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new MainApp());
		}
	}
}
