public static List<TaskResult> StartExport()
{
bw = new BackgroundWorker();
bw.DoWork += new DoWorkEventHandler(worker_Do);
bw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(worker_RunCompleted);
bw.RunWorkerAsync();
return Results;
}
感謝您想worker_RunCompleted後停止故事板是嗎?
檢查TaskCompletionSource :)
如果我理解正確的 - 這將是有益的。
_storyboard.Stop();
將_storyboardTaskCompletionSource
的結果設置爲RunWorkerCompleted
後引發。
private TaskCompletionSource<bool> _storyboardTaskCompletionSource;
Storyboard _storyboard = new Storyboard();
private async Task InitAsync()
{
_storyboardTaskCompletionSource = new TaskCompletionSource<bool>();
_storyboard.Begin();
StartProgress();
await _storyboardTaskCompletionSource.Task;
_storyboard.Stop();
}
public void StartProgress()
{
var bw = new BackgroundWorker();
bw.DoWork += DoWork;
bw.RunWorkerCompleted += RunWorkerCompleted;
bw.RunWorkerAsync();
}
private void RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
_storyboardTaskCompletionSource.SetResult(true);
}
private void DoWork(object sender, DoWorkEventArgs e)
{
//logic
}
你已經回答了你自己的問題,不是嗎?你有你需要的一切..... – kevintjuh93