这是我的代码:
private void TaskGestioneCartelle()
{
Task.Factory.StartNew(() => GeneraListaCartelle())
.ContinueWith(t => GeneraListaCartelleCompletata()
, CancellationToken.None
, TaskContinuationOptions.None
, TaskScheduler.FromCurrentSynchronizationContext());
}
private void GeneraListaCartelle()
{
// ... code
}
private void GeneraListaCartelleCompletata()
{
Task.Factory.StartNew(() => CopiaCartelle())
.ContinueWith(t => CopiaCartelleCompletato()
, CancellationToken.None
, TaskContinuationOptions.None
, TaskScheduler.FromCurrentSynchronizationContext());
}
private void CopiaCartelle()
{
if (txtLog.InvokeRequired)
{
txtLog.BeginInvoke(new MethodInvoker(delegate { txtLog.AppendText("Copio cartelle in corso..." + Environment.NewLine); }));
}
}
它启动一个线程。完成后,我启动另一个线程(从 Continue with)并尝试在 UI 上的 Control 中编写一些东西。但实际上什么都没有写txtLog
。我哪里错了?