This repository was archived by the owner on Jan 23, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed
src/System.ComponentModel.EventBasedAsync/tests Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -295,6 +295,39 @@ public void DisposeTwiceShouldNotThrow()
295
295
bw . Dispose ( ) ;
296
296
}
297
297
298
+ [ Fact ]
299
+ public void TestFinalization ( )
300
+ {
301
+ // BackgroundWorker has a finalizer that exists purely for backwards compatibility
302
+ // with existing code that may override Dispose to clean up native resources.
303
+ // https://github.com/dotnet/corefx/pull/752
304
+
305
+ ManualResetEventSlim mres = SetEventWhenFinalizedBackgroundWorker . CreateAndThrowAway ( ) ;
306
+
307
+ GC . Collect ( ) ;
308
+ GC . WaitForPendingFinalizers ( ) ;
309
+ GC . Collect ( ) ;
310
+
311
+ Assert . True ( mres . Wait ( 10000 ) ) ;
312
+ }
313
+
314
+ private sealed class SetEventWhenFinalizedBackgroundWorker : BackgroundWorker
315
+ {
316
+ private ManualResetEventSlim _setWhenFinalized ;
317
+
318
+ internal static ManualResetEventSlim CreateAndThrowAway ( )
319
+ {
320
+ var mres = new ManualResetEventSlim ( ) ;
321
+ new SetEventWhenFinalizedBackgroundWorker ( ) { _setWhenFinalized = mres } ;
322
+ return mres ;
323
+ }
324
+
325
+ protected override void Dispose ( bool disposing )
326
+ {
327
+ _setWhenFinalized . Set ( ) ;
328
+ }
329
+ }
330
+
298
331
private static void Wait ( int milliseconds )
299
332
{
300
333
Task . Delay ( milliseconds ) . Wait ( ) ;
You can’t perform that action at this time.
0 commit comments