我在Winform应用程序中的后台工作器中有一个循环.
我刚刚使用了此代码,但在暂停后它不会恢复.
在主类我使用这个
System.Threading.ManualResetEvent _busy = new System.Threading.ManualResetEvent(false);
然后在我的开始点击我写了这个:
if (!backgroundWorker1.IsBusy)
{
MessageBox.Show("Not Busy"); //Just For Debugg
_busy.Set();
Start_Back.Text = "Pause";
backgroundWorker1.RunWorkerAsync(tempCicle);
}
else
{
_busy.Reset();
Start_Back.Text = "Resume";
}
btnStop.Enabled = true;
Run Code Online (Sandbox Code Playgroud)
然后在backgroundworker doWork中我写了这个:
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
m_addTab addTabsInvoke = addTabUrl2;
Invoke(addTabsInvoke, "http://www.google.com");
foreach (something)
{
_busy.WaitOne();
if (backgroundWorker1.CancellationPending)
{
return;
}
if (tabs.InvokeRequired)
{
......
......
Run Code Online (Sandbox Code Playgroud)
我不明白为什么暂停工作,而简历不起作用.我错了什么?
我在 C# 中的 Windows 窗体应用程序有问题 在这个应用程序中有一个选项卡式浏览器。现在我想在一个循环中(我做一些操作来计算下一个 url)我可以在 AddTab 之间添加一个延迟。
IE
foreach(Urls url in Links){
// Do something with url
if(url.Host == "google"){ //if host is google until start the
// next AddTab i would wait 5 SEC
addTab(url);
//Here i Tried to use Sleep Thread , While(TimeCur-TimePre) {} but i always
// get Freezing and the other Tabs dont continue the loading
Wait 5 Seconds in somehow
}
}
Run Code Online (Sandbox Code Playgroud)
正如我所写,我不想使用线程睡眠,因为它会冻结我的表单应用程序。我已经在 TimeCur-TimeSaved+(x Second) 中使用了时间技巧,但这也会冻结表单。
我看到很多人说要使用计时器的主题,所以我尝试使用它们(没有任何结果,也许我错了)
我可以在这个循环中添加什么来延迟 AddTab 之间的打开而不冻结任何东西?