tpb*_*afk 0 c# multithreading while-loop
我有一个while循环检查true/false.And我也有阻止.如果块计数到300到0.我想杀死线程时它是0和另外两个地方.我看了论坛但我的方法看起来像有点不同.btw我试过中止但没有工作.如果我的帖子中有错误请edit.thx!
void Test()
{
Thread thread = new Thread(() =>
{
try
{
int countdown = 300;
while (true)
{
Thread.Sleep(1000);
paymentService.CheckPayment(pdId);
if (result.Complete == false)
{
countdown--;
if (countdown == 1)
{
//kill thread
}
}
if (result.Complete == true)
{
//kill thread
NavigationService.Navigate(new Uri("Pages/success.xaml", UriKind.Relative));
}
}
}
catch (Exception)
{
//kill thread
Application.Current.Shutdown();
}
});
thread.Start();
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
502 次 |
| 最近记录: |