Beispiel #1
0
 /// <summary>
 /// Executes the action within a safe context asynchronously.
 /// </summary>
 /// <param name="form">The form in which the action should be executed.</param>
 /// <param name="body">The body of the action to be executed.</param>
 /// <param name="initialize">The initializer action that will be invoked before the action body is executed.</param>
 /// <param name="cleanup">The cleanup action that will be invoked after the action body has been executed.</param>
 /// <param name="rethrowExceptionTypes">The <see cref="System.Exception"/> types that need to be rethrown to the upper level.</param>
 public static async Task ExecuteAsync(Form form, Func <Task> body, Action initialize = null, Action cleanup = null, params Type[] rethrowExceptionTypes)
 {
     try
     {
         form.Cursor = Cursors.WaitCursor;
         if (initialize != null)
         {
             initialize();
         }
         await body();
     }
     catch (Exception exc)
     {
         if (rethrowExceptionTypes != null &&
             rethrowExceptionTypes.Contains(exc.GetType()))
         {
             throw;
         }
         FrmExceptionDialog.ShowException(exc);
     }
     finally
     {
         if (cleanup != null)
         {
             cleanup();
         }
         form.Cursor = Cursors.Default;
     }
 }
Beispiel #2
0
        /// <summary>
        /// Shows the exception details in the dialog.
        /// </summary>
        /// <param name="ex">The exception to be shown in the dialog.</param>
        /// <returns></returns>
        public static DialogResult ShowException(Exception ex)
        {
            var excDialog = new FrmExceptionDialog
            {
                txtMessage = { Text = ex.Message },
                txtDetail  = { Text = ex.ToString() }
            };

            return(excDialog.ShowDialog());
        }
        /// <summary>
        /// Shows the exception details in the dialog.
        /// </summary>
        /// <param name="ex">The exception to be shown in the dialog.</param>
        /// <returns></returns>
        public static DialogResult ShowException(Exception ex)
        {
            var excDialog = new FrmExceptionDialog
                                {
                                    txtMessage = { Text = ex.Message },
                                    txtDetail = { Text = ex.ToString() }
                                };

            return excDialog.ShowDialog();
        }