@@ -21,6 +21,11 @@ public class MonitorCaptureConfiguration : IDisposable
21
21
private bool disposedValue = false ;
22
22
private static int MonitorSizeHint = 8 ;
23
23
24
+ private static MonitorWindowCallbackWithContext _onCaptureWithContext = OnCapture ;
25
+ private static ScreenCaptureCallbackWithContext _onNewFrameWithContext = OnNewFrame ;
26
+ private static ScreenCaptureCallbackWithContext _onFrameChangedWithContext = OnFrameChanged ;
27
+ private static MouseCaptureCallbackWithContext _onMouseChangedWithContext = OnMouseChanged ;
28
+
24
29
private static readonly UnmanagedHandles < MonitorCaptureConfiguration > UnmanagedHandles = new ( ) ;
25
30
26
31
public static Monitor [ ] GetMonitors ( )
@@ -72,7 +77,7 @@ public MonitorCaptureConfiguration(MonitorCallback callback)
72
77
{
73
78
_monitorCallback = callback ;
74
79
UnmanagedHandles . Add ( this , out _handle ) ;
75
- Config = NativeFunctions . SCL_CreateMonitorCaptureConfigurationWithContext ( OnCapture , _handle ) ;
80
+ Config = NativeFunctions . SCL_CreateMonitorCaptureConfigurationWithContext ( _onCaptureWithContext , _handle ) ;
76
81
}
77
82
catch
78
83
{
@@ -87,7 +92,7 @@ public MonitorCaptureConfiguration OnNewFrame(Action<Image, Monitor> onNewFrame)
87
92
if ( _onNewFrame == null )
88
93
{
89
94
_onNewFrame = onNewFrame ;
90
- NativeFunctions . SCL_MonitorOnNewFrameWithContext ( Config , OnNewFrame ) ;
95
+ NativeFunctions . SCL_MonitorOnNewFrameWithContext ( Config , _onNewFrameWithContext ) ;
91
96
}
92
97
else
93
98
{
@@ -104,7 +109,7 @@ public MonitorCaptureConfiguration OnFrameChanged(Action<Image, Monitor> onFrame
104
109
if ( _onFrameChanged == null )
105
110
{
106
111
_onFrameChanged = onFrameChanged ;
107
- NativeFunctions . SCL_MonitorOnFrameChangedWithContext ( Config , OnFrameChanged ) ;
112
+ NativeFunctions . SCL_MonitorOnFrameChangedWithContext ( Config , _onFrameChangedWithContext ) ;
108
113
}
109
114
else
110
115
{
@@ -121,7 +126,7 @@ public MonitorCaptureConfiguration OnMouseChanged(Action<Image, MousePoint> onMo
121
126
if ( _onMouseChanged == null )
122
127
{
123
128
_onMouseChanged = onMouseChanged ;
124
- NativeFunctions . SCL_MonitorOnMouseChangedWithContext ( Config , OnMouseChanged ) ;
129
+ NativeFunctions . SCL_MonitorOnMouseChangedWithContext ( Config , _onMouseChangedWithContext ) ;
125
130
}
126
131
else
127
132
{
0 commit comments