gpt4 book ai didi

c# - 此 BackgroundWorker 当前正忙,无法同时运行多个任务

转载 作者:IT王子 更新时间:2023-10-29 03:50:12 31 4
gpt4 key购买 nike

如果我点击两次启动后台程序的按钮,我会收到此错误。

This BackgroundWorker is currently busy and cannot run multiple tasks concurrently

我怎样才能避免这种情况?

最佳答案

很简单:不要启动 BackgroundWorker 两次。

您可以使用 IsBusy 属性检查它是否已经在运行,因此只需更改此代码:

worker.RunWorkerAsync();

为此:

if( !worker.IsBusy )
worker.RunWorkerAsync();
else
MessageBox.Show("Can't run the worker twice!");

更新:

如果确实需要同时启动多个后台任务,可以简单地创建多个BackgroundWorker对象

关于c# - 此 BackgroundWorker 当前正忙,无法同时运行多个任务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/588150/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com