You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
1.5 KiB
53 lines
1.5 KiB
// Needed for Workaround |
|
#if !NET_4_6 |
|
using System; |
|
using System.Threading; |
|
using LinqInternal.Collections.ThreadSafe; |
|
|
|
namespace LinqInternal.Threading |
|
{ |
|
internal static partial class GCMonitor |
|
{ |
|
private static class Internal |
|
{ |
|
private static readonly WeakDelegateCollection _collectedEventHandlers; |
|
private static readonly WaitCallback _work; |
|
|
|
static Internal() |
|
{ |
|
_work = _ => RaiseCollected(); |
|
_collectedEventHandlers = new WeakDelegateCollection(false, false, _maxProbingHint); |
|
} |
|
|
|
public static WeakDelegateCollection CollectedEventHandlers |
|
{ |
|
get { return _collectedEventHandlers; } |
|
} |
|
|
|
public static void Invoke() |
|
{ |
|
ThreadPool.QueueUserWorkItem(_work); |
|
} |
|
|
|
private static void RaiseCollected() |
|
{ |
|
var check = Volatile.Read(ref _status); |
|
if (check == _statusReady) |
|
{ |
|
try |
|
{ |
|
_collectedEventHandlers.RemoveDeadItems(); |
|
_collectedEventHandlers.Invoke(null, new EventArgs()); |
|
} |
|
catch (Exception exception) |
|
{ |
|
// Catch'em all |
|
GC.KeepAlive(exception); |
|
} |
|
Volatile.Write(ref _status, _statusReady); |
|
} |
|
} |
|
} |
|
} |
|
} |
|
#endif |