Last active
August 29, 2015 14:16
-
-
Save DVDPT/581a17abade5304b349f to your computer and use it in GitHub Desktop.
LoadingSafeRun
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
internal async Task LoadingSafeRun(Func<Task> func, string loadingMessage, bool startedByUser = false) | |
{ | |
try | |
{ | |
StartLoadingOperation(loadingMessage); | |
await func(); | |
StopLoadingOperation(); | |
} | |
catch (Exception e) | |
{ | |
StopLoadingOperation(); | |
var errorMessage = ExceptionHandlerService.Instance.Handle(exception); | |
if (startedByUser) | |
{ | |
try | |
{ | |
await MessageBoxService.ShowAsync(errorMessage, ErrorResources.Error, MessageBoxButton.Ok); | |
} | |
catch (Exception) | |
{ | |
} | |
} | |
else | |
{ | |
ShowErrorMessage(errorMessage); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment