void backgroundprocess(object param) { FormStarting fs = (FormStarting)param; Action<string> fpAddItem = AddItem; Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); string result; this.Invoke(fpAddItem, "加载视觉工具"); try { UVGlue.LoadVPP(); result = "成功"; this.Invoke(fpAddItem, result); fs.DialogResult = DialogResult.OK; Action actClose = () => { fs.Close(); }; fs.Invoke(actClose); } catch (Exception ex) { MessageBox.Show("视觉工具加载失败,请联系技术人员\r\n" + ex.Message); result = "失败"; this.Invoke(fpAddItem, result); fs.DialogResult = DialogResult.Cancel ; Action actClose = () => { fs.Close(); }; fs.Invoke(actClose); } }
static void Main(string[] args) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); // Exceptions handler var currentDomain = AppDomain.CurrentDomain; currentDomain.UnhandledException += (sender, eventArgs) => { UnhandledExceptionLogger.Log(UVGlue.logFile, (Exception)eventArgs.ExceptionObject, false); }; Application.ThreadException += (sender, eventArgs) => { UnhandledExceptionLogger.Log(UVGlue.logFile, eventArgs.Exception, false); }; Process instance = Misc.GetRunningInstance(); if (null != instance) { WinAPI.ShowWindowAsync(instance.MainWindowHandle, WinAPI.SW_SHOW); WinAPI.SetForegroundWindow(instance.MainWindowHandle); } else { UI.FormStarting fs = new UI.FormStarting(); Application.Run(fs); if (fs.DialogResult == DialogResult.OK) { UVGlue._formMain = new UI.FormMain(); Application.Run(UVGlue._formMain); } } }