@@ -82,50 +82,28 @@ public static void SetData(string name, object? data)
82
82
internal static event EventHandler < FirstChanceExceptionEventArgs > ? FirstChanceException ;
83
83
#pragma warning restore CS0067
84
84
85
- private static ulong s_crashingThreadId ;
86
-
87
85
#if NATIVEAOT
88
86
[ System . Runtime . RuntimeExport ( "OnUnhandledException" ) ]
89
87
#endif
90
88
internal static void OnUnhandledException ( object e )
91
89
{
92
- ulong currentThreadId = Thread . CurrentOSThreadId ;
93
- ulong previousCrashingThreadId = Interlocked . CompareExchange ( ref s_crashingThreadId , currentThreadId , 0 ) ;
94
- if ( previousCrashingThreadId == 0 )
95
- {
96
90
#if NATIVEAOT
97
- RuntimeExceptionHelpers . SerializeCrashInfo ( System . Runtime . RhFailFastReason . UnhandledException , ( e as Exception ) ? . Message , e as Exception ) ;
91
+ RuntimeExceptionHelpers . SerializeCrashInfo ( System . Runtime . RhFailFastReason . UnhandledException , ( e as Exception ) ? . Message , e as Exception ) ;
98
92
#endif
99
- if ( UnhandledException is UnhandledExceptionEventHandler handlers )
93
+ if ( UnhandledException is UnhandledExceptionEventHandler handlers )
94
+ {
95
+ UnhandledExceptionEventArgs args = new ( e , isTerminating : true ) ;
96
+ foreach ( UnhandledExceptionEventHandler handler in Delegate . EnumerateInvocationList ( handlers ) )
100
97
{
101
- UnhandledExceptionEventArgs args = new ( e , isTerminating : true ) ;
102
- foreach ( UnhandledExceptionEventHandler handler in Delegate . EnumerateInvocationList ( handlers ) )
98
+ try
99
+ {
100
+ handler ( /* AppDomain */ null ! , args ) ;
101
+ }
102
+ catch
103
103
{
104
- try
105
- {
106
- handler ( /* AppDomain */ null ! , args ) ;
107
- }
108
- catch
109
- {
110
- }
111
104
}
112
105
}
113
106
}
114
- else
115
- {
116
- if ( s_crashingThreadId == previousCrashingThreadId )
117
- {
118
- Environment . FailFast ( "OnUnhandledException called recursively" ) ;
119
- }
120
-
121
- // If we are already in the process of handling an unhandled
122
- // exception, we do not want to raise the event again. We wait
123
- // here while the other thread raises the unhandled exception.
124
- // Waiting is important because it is possible upon returning, this thread
125
- // could call some rude abort method that would terminate the process
126
- // before the other thread finishes raising the unhandled exception.
127
- Thread . Sleep ( - 1 ) ;
128
- }
129
107
}
130
108
131
109
internal static void OnProcessExit ( )
0 commit comments