Task t = new Task(() =>
            {
                while (true)
                {
                    this.Dispatcher.BeginInvoke(new Action(() =>
                    {
                        textBlock1.Text = DateTime.Now.ToString();
                    }));
                    Thread.Sleep(1000);
                }
            });
            //为了捕获异常,启动了一个新任务
            t.ContinueWith((task) =>
            {
                try
                {
                    task.Wait();
                }
                catch (AggregateException ex)
                {
                    foreach (Exception inner in ex.InnerExceptions)
                    {
                        MessageBox.Show(string.Format("异常类型:{0}{1}来自于:{2}{3}异常内容:{4}", inner.GetType(), Environment.NewLine, inner.Source, Environment.NewLine, inner.Message));
                    }
                }
            }, TaskContinuationOptions.OnlyOnFaulted);
            t.Start();

 C# WinForm 界面异步调用;

相关文章:

  • 2021-09-07
  • 2022-12-23
  • 2022-12-23
  • 2021-11-14
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-11-07
  • 2022-12-23
  • 2021-07-01
  • 2022-12-23
  • 2022-02-08
相关资源
相似解决方案