/// <summary> /// Shows a wait dialog that does not support cancelling. /// </summary> /// <param name="titleName">Title of the wait dialog</param> /// <param name="allowCancel">Specifies whether a cancel button should be shown.</param> /// <param name="defaultTaskName">The default description text, if no named task is active.</param> /// <returns>AsynchronousWaitDialog object - you can use it to access the wait dialog's properties. /// To close the wait dialog, call Dispose() on the AsynchronousWaitDialog object</returns> public static AsynchronousWaitDialog ShowWaitDialog(string titleName, string defaultTaskName, bool allowCancel) { if (titleName == null) { throw new ArgumentNullException("titleName"); } AsynchronousWaitDialog h = new AsynchronousWaitDialog(titleName, defaultTaskName, allowCancel, null); h.StartInThread(); return(h); }
/// <summary> /// Shows a wait dialog that does supports cancelling. /// </summary> /// <param name="titleName">Title of the wait dialog</param> /// <param name="defaultTaskName">The default description text, if no named task is active.</param> /// <param name="action">The action to run within the wait dialog</param> public static void RunInCancellableWaitDialog(string titleName, string defaultTaskName, Action <AsynchronousWaitDialog> action) { if (titleName == null) { throw new ArgumentNullException("titleName"); } using (AsynchronousWaitDialog h = new AsynchronousWaitDialog(titleName, defaultTaskName, true, null)) { h.StartInThread(); try { action(h); } catch (OperationCanceledException ex) { // consume OperationCanceledException if (ex.CancellationToken != h.CancellationToken) { throw; } } } }