2 using System
.Runtime
.InteropServices
;
7 public static bool fail
;
8 public static Test1 instance
;
11 if (self
.Target
== null)
19 public static bool fail
;
20 public static Test2 instance
;
23 if (self
.Target
== null)
30 public static int Main (String
[] args
) {
31 return TestDriver
.RunTests (typeof (Tests
), args
);
34 static void create1 () {
35 Test1
.instance
= new Test1 ();
36 Test1
.instance
.self
= GCHandle
.Alloc (Test1
.instance
, GCHandleType
.WeakTrackResurrection
);
37 Test1
.instance
= null;
40 public static unsafe int test_0_track_resurrection () {
41 /* The GCHandle should not be cleared before calling the finalizers */
44 GC
.WaitForPendingFinalizers ();
46 // WaitForPendingFinalizers doesn't seem to work ?
47 System
.Threading
.Thread
.Sleep (100);
48 /* If the finalizers do not get ran by this time, the test will still succeed */
49 return Test1
.fail
? 1 : 0;
52 static void create2 () {
53 Test2
.instance
= new Test2 ();
54 object o
= new object ();
55 Test2
.instance
.self
= GCHandle
.Alloc (o
, GCHandleType
.WeakTrackResurrection
);
56 Test2
.instance
.self
.Target
= Test2
.instance
;
57 Test2
.instance
= null;
60 public static int test_0_track_resurrection_set_target () {
61 /* Same test but the handle target is set dynamically after it is created */
64 GC
.WaitForPendingFinalizers ();
66 System
.Threading
.Thread
.Sleep (100);
67 return Test2
.fail
? 1 : 0;