VB.Net Threading —VB.Net 線程

在之前的網誌中, 說了怎樣使用BackgroundWorker,
今次想和大家介紹怎樣使用Threading 線程
有時候我們可以利用Threading 和執行一些需時/較複雜的程序
這樣便可以好像使用BackGroundWorker一樣
避免WinForm 出現假死/沒有回應的情況了

這次我也是建立了一個模擬一些需時/較複雜的程序

Public Sub LongProcess() '用來模擬一些Long Process的Code
Dim info As Integer = 0
For i As Integer = 0 To 999999
For j As Integer = 0 To 9999
info = i + j
Next
Next
btn_LongProcess.Text = Now.ToLongTimeString'完成時候 Update 這個Button 的文字為 現在的時間
MsgBox("Process Completed")

End Sub

之後我們可以建立一個Thread來處理這個 程序
使用方法十公簡單

'建立一個新的Thread線程, 設定他將會執行的功能名稱
Dim MyThreading As New System.Threading.Thread(AddressOf Me.LongProcess)
'用.Start來 啟動這個線程Thread</span>
MyThreading .Start()

Hope you find it useful

2 thoughts on “VB.Net Threading —VB.Net 線程

    1. ShareChiWai Post author

      Hi Jian, I am glad that you find this blog useful. Hopefully in near future I am going to upload a series of Windows 8 development with VS11 and TFS Express 11.

      Hope this will be useful too.

      Happy coding & have a good day

      Chi

      Reply

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.