c# - 链中的多个后台 worker

标签 c# .net multithreading backgroundworker

我有一系列 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/

相关文章:

c# - 在 Visual Studio Code 中恢复依赖项使用了错误的源/提要

c# - Microsoft 图形更改跟踪

c# - 免费的SQL Server存储过程生成器?

c# - 读取所有注册表值的快速方法

java - 我无法理解同步工作的示例如何

multithreading - 许多执行后,Delphi线程挂起

c# - Entity Framework 读取列但阻止更新

c# - Xamarin 如何仅在代码中绑定(bind)文本颜色

c# - 是否有一种简单的方法来导航 List<t> 对象?

c# - gRPC 间歇性地具有高延迟