public void Start(PeerCastApplication app) { System.Windows.Forms.Application.EnableVisualStyles(); mainThread = new Thread(() => { mainForm = new MainForm(app.PeerCast); System.Windows.Forms.Application.ApplicationExit += (sender, args) => { app.Stop(); }; System.Windows.Forms.Application.Run(mainForm); mainForm = null; }); mainThread.SetApartmentState(ApartmentState.STA); mainThread.Start(); }
protected override void OnStart() { System.Windows.Forms.Application.EnableVisualStyles(); mainThread = new Thread(() => { mainForm = new MainForm(Application); if (!mainForm.IsHandleCreated) { //ハンドルを強制的に作らせる var handle = mainForm.Handle; } System.Windows.Forms.Application.ApplicationExit += (sender, args) => { Application.Stop(); }; System.Windows.Forms.Application.Run(); mainForm = null; }); mainThread.SetApartmentState(ApartmentState.STA); mainThread.Start(); }