Skip to content

Commit 76e9f66

Browse files
Removed RunAsyncVoid method (#3466)
1 parent e8855c6 commit 76e9f66

File tree

8 files changed

+4
-57
lines changed

8 files changed

+4
-57
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77
- Client reports now include dropped spans ([#3463](https://github.com/getsentry/sentry-dotnet/pull/3463))
88

9+
### API Changes
10+
11+
- Removed SentrySdk.RunAsyncVoid ([#3466](https://github.com/getsentry/sentry-dotnet/pull/3466))
12+
913
## 4.8.1
1014

1115
### Fixes

samples/Sentry.Samples.Maui/MainPage.xaml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,6 @@
7070
Clicked="OnNativeCrashClicked"
7171
HorizontalOptions="Center" />
7272

73-
<Button
74-
x:Name="AsyncVoidCrashBtn"
75-
Text="Capture an exception from an async void method"
76-
SemanticProperties.Hint="Throws an exception in an async void event handler."
77-
Clicked="OnAsyncVoidCrashClicked"
78-
HorizontalOptions="Center" />
79-
8073
</VerticalStackLayout>
8174
</ScrollView>
8275

samples/Sentry.Samples.Maui/MainPage.xaml.cs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -88,21 +88,6 @@ private void OnNativeCrashClicked(object sender, EventArgs e)
8888
#endif
8989
}
9090

91-
private void OnAsyncVoidCrashClicked(object sender, EventArgs e)
92-
{
93-
var client = new HttpClient(new FlakyMessageHandler());
94-
95-
// You can use RunAsyncVoid to call async methods safely from within MAUI event handlers.
96-
SentrySdk.RunAsyncVoid(
97-
async () => await client.GetAsync("https://amostunreliablewebsite.net/"),
98-
ex => _logger.LogWarning(ex, "Error fetching data")
99-
);
100-
101-
// This is an example of the same, omitting any exception handler callback. In this case, the default exception
102-
// handler will be used, which simply captures any exceptions and sends these to Sentry
103-
SentrySdk.RunAsyncVoid(async () => await client.GetAsync("https://amostunreliablewebsite.net/"));
104-
}
105-
10691
private class FlakyMessageHandler : DelegatingHandler
10792
{
10893
protected override Task<HttpResponseMessage> SendAsync(

src/Sentry/SentrySdk.cs

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -691,37 +691,6 @@ public static void PauseSession()
691691
public static void ResumeSession()
692692
=> CurrentHub.ResumeSession();
693693

694-
/// <summary>
695-
/// Runs an `async void` method safely.
696-
/// </summary>
697-
/// <param name="task">Typically either a method group or an async lambda that executes some async void code</param>
698-
/// <param name="handler">
699-
/// An optional callback that will be run if an exception is thrown. If no callback is provided then by default the
700-
/// exception will be captured and sent to Sentry.
701-
/// </param>
702-
/// <example>
703-
/// <code>
704-
/// SentrySdk.RunAsyncVoid(async () => await MyAsyncMethod(), ex => Console.WriteLine(ex.Message));
705-
/// </code>
706-
/// </example>
707-
public static void RunAsyncVoid(Action task, Action<Exception>? handler = null)
708-
{
709-
var syncCtx = SynchronizationContext.Current;
710-
try
711-
{
712-
handler ??= DefaultExceptionHandler;
713-
SynchronizationContext.SetSynchronizationContext(new ExceptionHandlingSynchronizationContext(handler, syncCtx));
714-
task();
715-
}
716-
finally
717-
{
718-
SynchronizationContext.SetSynchronizationContext(syncCtx);
719-
}
720-
return;
721-
722-
void DefaultExceptionHandler(Exception ex) => CaptureException(ex);
723-
}
724-
725694
/// <summary>
726695
/// Deliberately crashes an application, which is useful for testing and demonstration purposes.
727696
/// </summary>

test/Sentry.Tests/ApiApprovalTests.Run.DotNet6_0.verified.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,6 @@ namespace Sentry
827827
public static System.IDisposable PushScope() { }
828828
public static System.IDisposable PushScope<TState>(TState state) { }
829829
public static void ResumeSession() { }
830-
public static void RunAsyncVoid(System.Action task, System.Action<System.Exception>? handler = null) { }
831830
public static void StartSession() { }
832831
public static Sentry.ITransactionTracer StartTransaction(Sentry.ITransactionContext context) { }
833832
public static Sentry.ITransactionTracer StartTransaction(Sentry.ITransactionContext context, System.Collections.Generic.IReadOnlyDictionary<string, object?> customSamplingContext) { }

test/Sentry.Tests/ApiApprovalTests.Run.DotNet7_0.verified.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,6 @@ namespace Sentry
827827
public static System.IDisposable PushScope() { }
828828
public static System.IDisposable PushScope<TState>(TState state) { }
829829
public static void ResumeSession() { }
830-
public static void RunAsyncVoid(System.Action task, System.Action<System.Exception>? handler = null) { }
831830
public static void StartSession() { }
832831
public static Sentry.ITransactionTracer StartTransaction(Sentry.ITransactionContext context) { }
833832
public static Sentry.ITransactionTracer StartTransaction(Sentry.ITransactionContext context, System.Collections.Generic.IReadOnlyDictionary<string, object?> customSamplingContext) { }

test/Sentry.Tests/ApiApprovalTests.Run.DotNet8_0.verified.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -829,7 +829,6 @@ namespace Sentry
829829
public static System.IDisposable PushScope() { }
830830
public static System.IDisposable PushScope<TState>(TState state) { }
831831
public static void ResumeSession() { }
832-
public static void RunAsyncVoid(System.Action task, System.Action<System.Exception>? handler = null) { }
833832
public static void StartSession() { }
834833
public static Sentry.ITransactionTracer StartTransaction(Sentry.ITransactionContext context) { }
835834
public static Sentry.ITransactionTracer StartTransaction(Sentry.ITransactionContext context, System.Collections.Generic.IReadOnlyDictionary<string, object?> customSamplingContext) { }

test/Sentry.Tests/ApiApprovalTests.Run.Net4_8.verified.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -824,7 +824,6 @@ namespace Sentry
824824
public static System.IDisposable PushScope() { }
825825
public static System.IDisposable PushScope<TState>(TState state) { }
826826
public static void ResumeSession() { }
827-
public static void RunAsyncVoid(System.Action task, System.Action<System.Exception>? handler = null) { }
828827
public static void StartSession() { }
829828
public static Sentry.ITransactionTracer StartTransaction(Sentry.ITransactionContext context) { }
830829
public static Sentry.ITransactionTracer StartTransaction(Sentry.ITransactionContext context, System.Collections.Generic.IReadOnlyDictionary<string, object?> customSamplingContext) { }

0 commit comments

Comments
 (0)