[Mwinapi-commits] SF.net SVN: mwinapi:[102] trunk/ManagedWinapi
Status: Beta
Brought to you by:
schierlm
|
From: <sch...@us...> - 2011-01-14 21:43:34
|
Revision: 102
http://mwinapi.svn.sourceforge.net/mwinapi/?rev=102&view=rev
Author: schierlm
Date: 2011-01-14 21:43:27 +0000 (Fri, 14 Jan 2011)
Log Message:
-----------
Make the EventDispatchingNativeWindow instance thread static, to make it work as expected in a multithreaded environment
Modified Paths:
--------------
trunk/ManagedWinapi/EventDispatchingNativeWindow.cs
trunk/ManagedWinapi/Hotkey.cs
trunk/ManagedWinapi/Mixer.cs
Modified: trunk/ManagedWinapi/EventDispatchingNativeWindow.cs
===================================================================
--- trunk/ManagedWinapi/EventDispatchingNativeWindow.cs 2011-01-13 21:44:46 UTC (rev 101)
+++ trunk/ManagedWinapi/EventDispatchingNativeWindow.cs 2011-01-14 21:43:27 UTC (rev 102)
@@ -44,6 +44,7 @@
{
private static Object myLock = new Object();
+ [ThreadStatic]
private static EventDispatchingNativeWindow _instance;
/// <summary>
Modified: trunk/ManagedWinapi/Hotkey.cs
===================================================================
--- trunk/ManagedWinapi/Hotkey.cs 2011-01-13 21:44:46 UTC (rev 101)
+++ trunk/ManagedWinapi/Hotkey.cs 2011-01-14 21:43:27 UTC (rev 102)
@@ -48,6 +48,7 @@
private Keys _keyCode;
private bool _ctrl, _alt, _shift, _windows;
private readonly IntPtr hWnd;
+ private readonly EventDispatchingNativeWindow nativeWindow;
/// <summary>
/// Initializes a new instance of this class with the specified container.
@@ -63,12 +64,13 @@
/// </summary>
public Hotkey()
{
- EventDispatchingNativeWindow.Instance.EventHandler += nw_EventHandler;
+ nativeWindow = EventDispatchingNativeWindow.Instance;
+ nativeWindow.EventHandler += nw_EventHandler;
lock(myStaticLock)
{
hotkeyIndex = ++hotkeyCounter;
}
- hWnd = EventDispatchingNativeWindow.Instance.Handle;
+ hWnd = nativeWindow.Handle;
}
/// <summary>
@@ -159,7 +161,7 @@
{
isDisposed = true;
updateHotkey(false);
- EventDispatchingNativeWindow.Instance.EventHandler -= nw_EventHandler;
+ nativeWindow.EventHandler -= nw_EventHandler;
base.Dispose(disposing);
}
Modified: trunk/ManagedWinapi/Mixer.cs
===================================================================
--- trunk/ManagedWinapi/Mixer.cs 2011-01-13 21:44:46 UTC (rev 101)
+++ trunk/ManagedWinapi/Mixer.cs 2011-01-14 21:43:27 UTC (rev 102)
@@ -66,6 +66,7 @@
private MIXERCAPS mc;
private IList<DestinationLine> destLines = null;
private bool createEvents;
+ private readonly EventDispatchingNativeWindow nativeWindow;
/// <summary>
/// Occurs when a control of this mixer changes value.
@@ -80,7 +81,8 @@
private Mixer(IntPtr hMixer)
{
this.hMixer = hMixer;
- EventDispatchingNativeWindow.Instance.EventHandler += ednw_EventHandler;
+ nativeWindow = EventDispatchingNativeWindow.Instance;
+ nativeWindow.EventHandler += ednw_EventHandler;
mixerGetDevCapsA(hMixer, ref mc, Marshal.SizeOf(mc));
}
@@ -188,7 +190,7 @@
if (hMixer.ToInt32() != 0)
{
mixerClose(hMixer);
- EventDispatchingNativeWindow.Instance.EventHandler -= ednw_EventHandler;
+ nativeWindow.EventHandler -= ednw_EventHandler;
hMixer = IntPtr.Zero;
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|