今天看到一篇關於“多線程”的例子,感覺比較形象,於是動手操作了一下。
原文出處:http://dev.21tx.com/2006/07/05/11760.html
由於之前自己看到的沒有圖片,於是就是憑文字介紹按部就班地實踐了一下;故有點差異,有興趣地話自己也可以動手完善一下。
原始碼:http://files.cnblogs.com/zzc315/httpftp_20070808.rar
我的開發環境是:Microsoft Visual Studio 2005;故和作者的開發環境(Visual Studio.net 2002開發環境及Windows xp 作業系統)有所差異,遇到:
資料參考:http://msdn2.microsoft.com/zh-cn/library/ms171728(VS.80).aspx#Mtps_DropDownFilterText
解決方案:
//Form1.cs
delegate void SetListBoxCallback(string listBox);
……
public void SetListBox(string listBox)
{
// InvokeRequired required compares the thread ID of the
// calling thread to the thread ID of the creating thread.
// If these threads are different, it returns true.
if (this.listBox1.InvokeRequired)
{
SetListBoxCallback d = new SetListBoxCallback(SetListBox);
this.Invoke(d, new object[] { listBox });
}
else
{
this.listBox1.Items.Add(listBox);
}
}
//HttpFile.cs
//formm.listBox1.Items.Add("線程" + threadh.ToString() + "開始接收");
formm.SetListBox("線程" + threadh.ToString() + "開始接收");
1.最近在看一些“多線程”方面的基本知識,感覺這個例子比較經典,且比較有趣,所有和大家分享一下;
2.如有學習“多線程”方面好的建議或意見,或相關資料,感謝大家一同來探討學習。