本文介绍了线程结束后执行一条语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个在c#.net中使用过线程的函数.
I am having a function where I have used a thread in c#.net.
我在该线程的下一行具有另一个功能.但是只有在线程执行后才必须调用此函数.
I am having a another function on the next line of that thread. But this function has to be called only after the thread gets executed.
我该怎么办?
示例..
Somefunction()
{
// thread //(thread started)
add() (another function but need to be executed only tha above thread gets over)
}
推荐答案
使用BackgroundWorker,并将函数调用包括在worker完成的事件处理程序中.
Use a BackgroundWorker and include the function call in the worker completeted event handler.
var worker = new BackgroundWorker();
_worker.DoWork += delegate { DoStuff(); };
_worker.RunWorkerCompleted += worker_RunWorkerCompleted;
_worker.RunWorkerAsync();
[...]
private void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) {
/// Do post-thread stuff
}
这篇关于线程结束后执行一条语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!