线程问题:我如何知道线程已经结束了?

farrio 2005-03-28 05:46:55
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
...全文
268 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
美福种田伯 2005-03-28
  • 打赏
  • 举报
回复
建立事件委托 建立一个结束进程的事件 事件引发后自动记数
delphi_dcs 2005-03-28
  • 打赏
  • 举报
回复
問題解決沒有
athossmth 2005-03-28
  • 打赏
  • 举报
回复
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();
}
}
gyf19 2005-03-28
  • 打赏
  • 举报
回复
你访问t.ThreadState属性它能返回t线程的状态!!

获取一个值,该值包含当前线程的状态。
3tzjq 2005-03-28
  • 打赏
  • 举报
回复
If th.ThreadState = Threading.ThreadState.Stopped Then Debug.WriteLine("线程已经停止!")

16,554

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧