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]