1 回答

TA貢獻1854條經驗 獲得超8個贊
正如我在評論中提到的,您的 lambda for 不知道它是否在循環中被調用,因此沒有可用的。您需要 使用 來退出等待的任務,以便您的代碼可以在等待的任務之后繼續。Dispatcher.InvokeAsynccontinuereturn
bool isNude = false;
var SearchTask = Task.Run(async () =>
{
foreach (var file in await GetFileListAsync(GlobalData.Config.DataPath))
{
isNude = false;
if (!ct.IsCancellationRequested)
{
await Dispatcher.InvokeAsync(() =>
{
if (ButtonNude.IsChecked == true)
{
foreach (var itemx in nudeData)
{
if (itemx.Equals(Path.GetFileNameWithoutExtension(file.FullName)))
{
isNude = true;
break;
}
}
}
if (isNude)
return; // continue -> return
// other code
}, DispatcherPriority.Background);
// <--- code continues here after return
}
}
}, ct);
- 1 回答
- 0 關注
- 96 瀏覽
添加回答
舉報