-
Notifications
You must be signed in to change notification settings - Fork 123
Expand file tree
/
Copy pathWeakReference.cs
More file actions
36 lines (32 loc) · 888 Bytes
/
WeakReference.cs
File metadata and controls
36 lines (32 loc) · 888 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
// Wrapper around System.WeakReference until XAML removes its dependency on it.
namespace WinRT
{
public sealed class WeakReference<T>
where T : class
{
private System.WeakReference<T> _managedWeakReference;
public WeakReference(T target)
{
_managedWeakReference = new System.WeakReference<T>(target);
}
public void SetTarget(T target)
{
lock (_managedWeakReference)
{
_managedWeakReference.SetTarget(target);
}
}
public bool TryGetTarget(out T target)
{
lock (_managedWeakReference)
{
return _managedWeakReference.TryGetTarget(out target);
}
}
}
}