我有一系列 3 个耗时函数,我想在后台工作程序或任何其他工具中执行它们,我的问题是每个函数都应该等待先例函数完成,所以这是我的伪代码:
open_session() // during the execution of this function i like to display a loading-window
open_session() //this function opens a process another windows app , while opening this app i would like to keep the current app responsive.
close_session()// during the execution of this function i like to display a loading-window
我想用后台 worker 来做这件事,但是做函数是异步的。
请帮忙
最佳答案
为什么不在同一个后台 worker 中依次执行这三个呢?因此,您的 backgroundworker 工作事件将如下所示:
private void yourBackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
{
open_session();
open_session();
close_session();
}
那样的话,backgroundworker 本身是异步的,但是您想要顺序运行的三个方法仍然在异步方法的上下文中顺序运行。
关于c# - 链中的多个后台 worker ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11909097/