private void LogMessage(string message) { Win32Util.ExecuteOrInvoke(this, () => { labelMessage.Text = message; }); }
private void InvokeLoadMainPackage() { Win32Util.ExecuteOrInvoke(this, () => { panelCancel.Visible = true; }); Action actionLoadMain = new Action(LoadMainPackage); actionLoadMain.BeginInvoke(LoadMainPackageCallback, actionLoadMain); }
private void ExecuteAsyncWithWait(Action method, AutoResetEvent cancelEvent, string message) { StartScreenForm form = new StartScreenForm(cancelEvent, message); method.BeginInvoke(ar => { try { Win32Util.ExecuteOrInvoke(form, form.Close); method.EndInvoke(ar); } catch (Exception ex) { Win32Util.ShowError(this, "Не удалось выполнить операцию. Описание ошибки приведено далее. \r\n" + ex.Message + "\r\n" + ex.StackTrace); } }, null); if (form.ShowDialog() == DialogResult.Cancel && cancelEvent != null) { cancelEvent.Set(); } }
void execCallback(IAsyncResult result) { _context.Log.AddLogInformation("Вход в execCallback"); try { ExecutePackageAsyncState state = (ExecutePackageAsyncState)result.AsyncState; state.action.EndInvoke(result); Win32Util.ExecuteOrInvoke(this, () => { buttonBrowse.Enabled = true; panelCancel.Visible = false; MessageBox.Show(this, "Пакет выполнен успешно", "Выполнение пакета завершено", MessageBoxButtons.OK, MessageBoxIcon.Information); panelMain.Controls.Clear(); }); } catch (Exception ex) { _context.Log.AddLogInformation("Поймано исключение в execCallback. Подробности смотрите далее."); _context.Log.AddLogException(ex); Win32Util.ShowError(this, "Ошибка при выполнении пакета. Подробности можно найти в журнале инсталлятора."); } _context.Log.AddLogInformation("Выход из execCallback"); }
void loadCallback(IAsyncResult result) { _context.Log.AddLogInformation("Вход в loadCallback"); try { Func <string, string> load = (Func <string, string>)result.AsyncState; load.EndInvoke(result); _context.Log.AddLogInformation("Пакет загружен."); Action exec = new Action(_package.Execute); ExecutePackageAsyncState state = new ExecutePackageAsyncState() { action = exec, package = _package }; _context.Log.AddLogInformation("Начинаем выполнение пакета"); exec.BeginInvoke(execCallback, state); } catch (PackageExecutionCancelledException) { Win32Util.ExecuteOrInvoke(this, () => { buttonBrowse.Enabled = true; panelCancel.Visible = false; MessageBox.Show(this, "Прервано пользователем", "Ошибка при выполнении пакета", MessageBoxButtons.OK, MessageBoxIcon.Error); panelMain.Controls.Clear(); }); } catch (Exception ex) { _context.Log.AddLogInformation("Поймано исключение в loadCallback. Подробности смотрите далее."); _context.Log.AddLogException(ex); Win32Util.ShowError(this, "Ошибка при выполнении пакета. Подробности можно найти в журнале инсталлятора."); } _context.Log.AddLogInformation("Выход из loadCallback"); }
private void CloseForm() { Win32Util.ExecuteOrInvoke(this, Close); }