C# WinForms: How to set Main function STAThreadAttribute

前端 未结 5 1659
轮回少年
轮回少年 2020-11-27 06:55

I get the following exception when calling saveFileDialog.ShowDialog() in a background thread:

Current thread must be set to single thr

5条回答
  •  自闭症患者
    2020-11-27 07:22

    ShowDialog() shouldn't be called from a background thread - use Invoke(..).

    Invoke((Action)(() => { saveFileDialog.ShowDialog() }));
    

提交回复
热议问题