使用线程时交叉线程错误

时间:2017-11-04 06:23:53

标签: c# winforms

我想在一些操作后使用线程并关闭我的表单。但是我得到一个交叉线程错误.solutions?

     new System.Threading.Thread(s =>
        {  
            Close;   }).Start();

1 个答案:

答案 0 :(得分:-1)

你必须关闭(); WPF中的声明

Application.Current.Dispatcher.Invoke(() =>
{
     // Code to run on the UI thread.
});

并在此为WinForms

this.BeginInvoke(new MethodInvoker(delegate 
{
    // Code to run on the UI thread.
});