diff --git a/NTwain/TwainSessionBase.cs b/NTwain/TwainSessionBase.cs index 5886ff1..eca15d9 100644 --- a/NTwain/TwainSessionBase.cs +++ b/NTwain/TwainSessionBase.cs @@ -576,9 +576,10 @@ namespace NTwain TWEvent evt = new TWEvent(); evt.pEvent = msgPtr; - handled = DGControl.Event.ProcessEvent(evt) == ReturnCode.DSEvent; - - HandleSourceMsg(evt.TWMessage); + if (handled = DGControl.Event.ProcessEvent(evt) == ReturnCode.DSEvent) + { + HandleSourceMsg(evt.TWMessage); + } } finally { @@ -604,7 +605,7 @@ namespace NTwain var ctx = o as SynchronizationContext; if (ctx != null) { - _syncer.Send(blah => + _syncer.Post(blah => { HandleSourceMsg(msg); }, null); @@ -623,10 +624,7 @@ namespace NTwain // method that handles msg from the source, whether it's from wndproc or callbacks void HandleSourceMsg(Message msg) { - if (msg != Message.Null) - { - Debug.WriteLine(string.Format("Thread {0}: HandleSourceMsg at state {1} with MSG={2}.", Thread.CurrentThread.ManagedThreadId, State, msg)); - } + Debug.WriteLine(string.Format("Thread {0}: HandleSourceMsg at state {1} with MSG={2}.", Thread.CurrentThread.ManagedThreadId, State, msg)); switch (msg) { diff --git a/Tests/Tester.WPF/MainWindow.xaml.cs b/Tests/Tester.WPF/MainWindow.xaml.cs index 44ae85b..9a040ab 100644 --- a/Tests/Tester.WPF/MainWindow.xaml.cs +++ b/Tests/Tester.WPF/MainWindow.xaml.cs @@ -18,6 +18,7 @@ using System.Windows.Interop; using System.Runtime.InteropServices; using CommonWin32; using System.Threading; +using ModernWPF.Controls; namespace Tester.WPF { @@ -79,7 +80,7 @@ namespace Tester.WPF var rc2 = twain.CloseSource(); rc2 = twain.CloseManager(); - MessageBox.Show("Success!"); + ModernMessageBox.Show(this, "Success!"); }; twain.TransferReady += (s, te) => { @@ -92,7 +93,7 @@ namespace Tester.WPF //} //else //{ - //te.OutputFile = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "test.bmp"); + //te.OutputFile = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "test.bmp"); //} }; } @@ -157,7 +158,7 @@ namespace Tester.WPF twain.DGControl.Status.GetManager(out status); } - MessageBox.Show(string.Format("Step {0}: RC={1}, CC={2}", step, rc, status.ConditionCode)); + ModernMessageBox.Show(this, string.Format("Step {0}: RC={1}, CC={2}", step, rc, status.ConditionCode)); } } }