在学习这个部分之前,搜索了很多资料,也看了很多源代码。但是再看看微软的MSDN发现,网上流传的与MSDN (.NET 2.0) 的说法完全不同。于是我很茫然,一直以为C# 2.0 怎么这么难啊。
但是今天,别人说C#原来这么简单的说法,又一次得到了我自己的同感。
很多人说,在.NET框架中,启动多线程,需要使用Thread空间,这的确不错。不过,对于我这样的初学者,我可以只使用BackgroundWoker控件来实现。
很多人说,要在多线程中传递数据,需要设置一个包装的类什么的,总之好像很麻烦的样子。因为我现在还是不清楚,所以也不知道该怎么写。不过,我这个初学者,也找到了自己的解决办法,那就是设置全局变量,直接传递数据,不过,在同步数据之前可以将全局变量lock一下,来保证安全。嘿嘿。
下面就把我个人的拙作,献丑一下,请多多包涵。如果您发现我有哪里做得不好,请多多评批指正。

  1namespace 多线程1
  2{
  3    partial class Form1
  4    {
  5        /// <summary>
  6        /// 必需的设计器变量。
  7        /// </summary>

  8        private System.ComponentModel.IContainer components = null;
  9
 10        /// <summary>
 11        /// 清理所有正在使用的资源。
 12        /// </summary>
 13        /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>

 14        protected override void Dispose(bool disposing)
 15        {
 16            if (disposing && (components != null))
 17            {
 18                components.Dispose();
 19            }

 20            base.Dispose(disposing);
 21        }

 22
 23        Windows 窗体设计器生成的代码
136
137        private System.Windows.Forms.Label label5;
138        private System.Windows.Forms.Label labelTimeReal;
139        private System.Windows.Forms.Label label7;
140        private System.Windows.Forms.Label labelTimeCount;
141        private System.Windows.Forms.TextBox textBoxURI;
142        private System.Windows.Forms.Button buttonDownload;
143        private System.Windows.Forms.TextBox textBox1;
144        private System.Windows.Forms.Timer timer1;
145        private System.ComponentModel.BackgroundWorker backgroundWorker1;
146    }

147}

148
149