C# WinForms: How to set Main function STAThreadAttribute

前端 未结 5 1704
轮回少年
轮回少年 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:09

    Solution very easy; Just add this on top of the Main method [STAThread]

    So your main method should look like this

     [STAThread]
     static void Main(string[] args)
     {
         ....
     }
    

    It works for me.

提交回复
热议问题