Skip to content

Commit 4037146

Browse files
committed
[Sentry] Detach StopSentrySdk to prevent UI thread stuck on disable
1 parent d42bcef commit 4037146

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

Hi3Helper.Core/Classes/SentryHelper/SentryHelper.cs

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -168,21 +168,25 @@ public static void InitializeSentrySdk()
168168
/// </summary>
169169
public static void StopSentrySdk()
170170
{
171-
try
172-
{
173-
SentrySdk.Flush(TimeSpan.FromSeconds(5));
174-
SentrySdk.EndSession();
175-
ReleaseExceptionRedirect();
176-
}
177-
catch (Exception ex)
178-
{
179-
Logger.LogWriteLine($"Failed when preparing to stop SentryInstance, Dispose will still be invoked!\r\n{ex}"
180-
, LogType.Error, true);
181-
}
182-
finally
183-
{
184-
_sentryInstance?.Dispose();
185-
}
171+
_ = Task.Run(async () =>
172+
{
173+
try
174+
{
175+
await SentrySdk.FlushAsync(TimeSpan.FromSeconds(5));
176+
SentrySdk.EndSession();
177+
ReleaseExceptionRedirect();
178+
}
179+
catch (Exception ex)
180+
{
181+
Logger
182+
.LogWriteLine($"Failed when preparing to stop SentryInstance, Dispose will still be invoked!\r\n{ex}",
183+
LogType.Error, true);
184+
}
185+
finally
186+
{
187+
_sentryInstance?.Dispose();
188+
}
189+
});
186190
}
187191

188192
public static void InitializeExceptionRedirect()

0 commit comments

Comments
 (0)