线程问题:我如何知道线程已经结束了?
WindowsApplication里面,新New一个线程,然后Start。等待线程结束后有一些操作要在主线程里面执行。我怎么知道我新New的线程结束了呢?
Private Sub btnGo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGo.Click
t = New Threading.Thread(AddressOf WinTree)
t.Start()
Me.txtTree.Text = val
End Sub
Private Sub WinTree()
WinTree(dir, "", val)
End Sub
问题点数:80、回复次数:5Top
1 楼3tzjq(永不言弃)回复于 2005-03-28 18:03:10 得分 16
If th.ThreadState = Threading.ThreadState.Stopped Then Debug.WriteLine("线程已经停止!")Top
2 楼gyf19(秋天的云)回复于 2005-03-28 18:07:42 得分 16
你访问t.ThreadState属性它能返回t线程的状态!!
获取一个值,该值包含当前线程的状态。
Top
3 楼athossmth(athos)回复于 2005-03-28 18:15:57 得分 16
using System;
using System.Threading;
class App {
public static void Main() {
Console.WriteLine("Main thread: Queuing an asynchronous operation.");
AutoResetEvent asyncOpIsDone = new AutoResetEvent(false);
ThreadPool.QueueUserWorkItem(new WaitCallback(MyAsyncOperation), asyncOpIsDone);
Console.WriteLine("Main thread: Performing other operations.");
// ...
Console.WriteLine("Main thread: Waiting for asynchronous operation to complete.");
asyncOpIsDone.WaitOne();
}
// The callback method's signature MUST match that of a System.Threading.WaitCallback
// delegate (it takes an Object parameter and returns void)
static void MyAsyncOperation(Object state) {
Console.WriteLine("WorkItem thread: Performing asynchronous operation.");
// ...
Thread.Sleep(5000); // Sleep for 5 seconds to simulate doing work
// Signal that the async operation is now complete.
((AutoResetEvent)state).Set();
}
}Top
4 楼delphi_dcs(delphi人生)回复于 2005-03-28 18:23:36 得分 16
問題解決沒有Top
5 楼Drong([伤口])回复于 2005-03-28 18:53:08 得分 16
建立事件委托 建立一个结束进程的事件 事件引发后自动记数Top




