Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
Gen2GcCallback.cs
Go to the documentation of this file.
3
4namespace System;
5
7{
8 private readonly Func<bool> _callback0;
9
10 private readonly Func<object, bool> _callback1;
11
13
14 private Gen2GcCallback(Func<bool> callback)
15 {
16 _callback0 = callback;
17 }
18
19 private Gen2GcCallback(Func<object, bool> callback, object targetObj)
20 {
21 _callback1 = callback;
22 _weakTargetObj = GCHandle.Alloc(targetObj, GCHandleType.Weak);
23 }
24
25 public static void Register(Func<bool> callback)
26 {
27 new Gen2GcCallback(callback);
28 }
29
30 public static void Register(Func<object, bool> callback, object targetObj)
31 {
32 new Gen2GcCallback(callback, targetObj);
33 }
34
36 {
38 {
39 object target = _weakTargetObj.Target;
40 if (target == null)
41 {
43 return;
44 }
45 try
46 {
47 if (!_callback1(target))
48 {
50 return;
51 }
52 }
53 catch
54 {
55 }
56 }
57 else
58 {
59 try
60 {
61 if (!_callback0())
62 {
63 return;
64 }
65 }
66 catch
67 {
68 }
69 }
71 }
72}
static void ReRegisterForFinalize(object obj)
Definition GC.cs:214
Definition GC.cs:8
static void Register(Func< bool > callback)
Gen2GcCallback(Func< bool > callback)
readonly Func< bool > _callback0
static void Register(Func< object, bool > callback, object targetObj)
readonly Func< object, bool > _callback1
Gen2GcCallback(Func< object, bool > callback, object targetObj)
static GCHandle Alloc(object? value)
Definition GCHandle.cs:81