调用线程务必为 STA,因为许多 UI 组件都需要

调用线程必须为 STA,因为许多 UI 组件都需要class Mainclass{[STAThread]static void Main(){Application

调用线程必须为 STA,因为许多 UI 组件都需要

class Mainclass    {        [STAThread]        static void Main()        {            Application app = new Application();            MainWindow win = new MainWindow();            app.Startup += new StartupEventHandler(app_Startup);            app.Run();        }        static void app_Startup(object sender,StartupEventArgs e)        {            MessageBox.Show("fdf");        }    }

需要在 Main() 方法前添加 [STAThread]