c#子线程线程中操作窗体更新的报错

在执行上传时,由于操作较长窗体界面卡住,于是用task解决

Task t1 = new Task(manage.UploadData);
t1.Start(); 

结果不卡了,程序也传完了,运行到更新控件状态时报错, 看来task内控制窗体存在跨线程的问题,尽管我的model模块里边用了invoke 还是报下边的错误

这是在数据源内定义的更新控件的方法 

  protected void OnPropertyChanged(string name)
        { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name)); }

看来线程的执行位置还得往下移到上传那一段代码上

其他信息: SFTP文件上传失败,原因:Cross thread operation detected. To suppress this exception, set DevExpress.Data.CurrencyDataController.DisableThreadingProblemsDetection = true

也可以加上上边的代码

namespace WindowsApplication1 {
    static class Program {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main() {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            DevExpress.UserSkins.OfficeSkins.Register();
            DevExpress.UserSkins.BonusSkins.Register();
            DevExpress.Data.CurrencyDataController.DisableThreadingProblemsDetection = true;
            Application.Run(new Form1());
        }
    }
原文地址:https://www.cnblogs.com/zuochanzi/p/8991936.html