override protected 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();
}