/
githubmirror
/
aspnetcore
Обзор
Документация
Войти
/
githubmirror
/
aspnetcore
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/Components/test/testassets/Components.TestServer/UnobservedTaskExceptionObserver.cs
39 строк
1 KB
Ilona Tomkowicz
Fix for Unobserved `NavigationException` in Blazor SSR (#62554)
07 июл 2025, 09:39
Не верифицирован
07 июл 2025, 09:39
c3fa2bb
Код
Авторство
О чём код?
// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using System.Collections.Concurrent; using System.Threading; namespace TestServer; public class UnobservedTaskExceptionObserver { private readonly ConcurrentQueue<Exception> _exceptions = new(); private int _circularRedirectCount; public void OnUnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs e) { _exceptions.Enqueue(e.Exception); e.SetObserved(); // Mark as observed to prevent the process from crashing during tests } public bool HasExceptions => !_exceptions.IsEmpty; public IReadOnlyCollection<Exception> GetExceptions() => _exceptions.ToArray(); public void Clear() { _exceptions.Clear(); _circularRedirectCount = 0; } public int GetCircularRedirectCount() { return _circularRedirectCount; } public int GetAndIncrementCircularRedirectCount() { return Interlocked.Increment(ref _circularRedirectCount) - 1; } }