Skip to content

Commit

Permalink
Add RemoveDefaultExceptionHandling
Browse files Browse the repository at this point in the history
  • Loading branch information
TheCodeTraveler committed Jul 31, 2019
1 parent d194148 commit f18c3b3
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,16 @@ void InitializeSafeFireAndForget()
SafeFireAndForgetExtensions.SetDefaultExceptionHandling(ex => Console.WriteLine(ex));
}

void UninitializeSafeFireAndForget()
{
// Remove default exception handling
SafeFireAndForgetExtensions.RemoveDefaultExceptionHandling()
}

void HandleButtonTapped(object sender, EventArgs e)
{
// Allows the async Task method to safely run on a different thread while not awaiting its completion
// onException: If a WebException is thrown, print its StatusCode to the Console. **Note**: If a non-WebException is thrown, it will not be handled by `onException`
// Because we set `SetDefaultExceptionHandling` in `void InitializeSafeFireAndForget()`, the entire exception will also be printed to the Console
ExampleAsyncMethod().SafeFireAndForget<WebException>(onException: ex =>
{
Expand All @@ -163,7 +167,6 @@ void HandleButtonTapped(object sender, EventArgs e)
});

// HandleButtonTapped continues execution here while `ExampleAsyncMethod()` is running on a different thread
// ...
}

async Task ExampleAsyncMethod()
Expand All @@ -190,7 +193,7 @@ public event EventHandler CanExecuteChanged
remove => _weakEventManager.RemoveEventHandler(value);
}

public void OnCanExecuteChanged() => _canExecuteChangedEventManager.HandleEvent(this, EventArgs.Empty, nameof(CanExecuteChanged));
void OnCanExecuteChanged() => _canExecuteChangedEventManager.HandleEvent(this, EventArgs.Empty, nameof(CanExecuteChanged));
```

#### Using `Delegate`
Expand All @@ -204,7 +207,7 @@ public event PropertyChangedEventHandler PropertyChanged
remove => _propertyChangedEventManager.RemoveEventHandler(value);
}

public void OnPropertyChanged([CallerMemberName]string propertyName = "") => _propertyChangedEventManager.HandleEvent(this, new PropertyChangedEventArgs(propertyName), nameof(PropertyChanged));
void OnPropertyChanged([CallerMemberName]string propertyName = "") => _propertyChangedEventManager.HandleEvent(this, new PropertyChangedEventArgs(propertyName), nameof(PropertyChanged));
```

#### Using `Action`
Expand All @@ -218,7 +221,7 @@ public event Action ActionEvent
remove => _weakActionEventManager.RemoveEventHandler(value);
}

public void OnActionEvent(string message) => _weakActionEventManager.HandleEvent(message, nameof(ActionEvent));
void OnActionEvent(string message) => _weakActionEventManager.HandleEvent(message, nameof(ActionEvent));
```

### `WeakEventManager<T>`
Expand All @@ -235,7 +238,7 @@ public event EventHandler<string> ErrorOcurred
remove => _errorOcurredEventManager.RemoveEventHandler(value);
}

public void OnErrorOcurred(string message) => _errorOcurredEventManager.HandleEvent(this, message, nameof(ErrorOcurred));
void OnErrorOcurred(string message) => _errorOcurredEventManager.HandleEvent(this, message, nameof(ErrorOcurred));
```

#### Using `Action<T>`
Expand All @@ -249,7 +252,7 @@ public event Action<string> ActionEvent
remove => _weakActionEventManager.RemoveEventHandler(value);
}

public void OnActionEvent(string message) => _weakActionEventManager.HandleEvent(message, nameof(ActionEvent));
void OnActionEvent(string message) => _weakActionEventManager.HandleEvent(message, nameof(ActionEvent));
```

## AsyncAwaitBestPractices.MVVM
Expand Down

0 comments on commit f18c3b3

Please sign in to comment.