mirror of
https://github.com/soukoku/ntwain.git
synced 2025-09-18 17:47:57 +08:00
small hack to handle disablesource called from diff threads for #16
This commit is contained in:
@@ -41,7 +41,10 @@ namespace NTwain
|
||||
|
||||
_appId = appId;
|
||||
((ITwainSessionInternal)this).ChangeState(1, false);
|
||||
#if DEBUG
|
||||
// defaults to false on release since it's only useful during dev
|
||||
EnforceState = true;
|
||||
#endif
|
||||
}
|
||||
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
|
||||
@@ -434,7 +437,7 @@ namespace NTwain
|
||||
|
||||
_msgLoopHook.Invoke(() =>
|
||||
{
|
||||
Debug.WriteLine(string.Format(CultureInfo.InvariantCulture, "Thread {0}: EnableSource.", Thread.CurrentThread.ManagedThreadId));
|
||||
Debug.WriteLine(string.Format(CultureInfo.InvariantCulture, "Thread {0}: EnableSource with {1}.", Thread.CurrentThread.ManagedThreadId, mode));
|
||||
|
||||
// app v2.2 or higher uses callback2
|
||||
if (_appId.ProtocolMajor >= 2 && _appId.ProtocolMinor >= 2)
|
||||
@@ -483,21 +486,32 @@ namespace NTwain
|
||||
return rc;
|
||||
}
|
||||
|
||||
bool _disabling;
|
||||
ReturnCode ITwainSessionInternal.DisableSource()
|
||||
{
|
||||
var rc = ReturnCode.Failure;
|
||||
|
||||
_msgLoopHook.Invoke(() =>
|
||||
if (!_disabling) // temp hack as a workaround to this being called from multiple threads (xfer logic & closedsreq msg)
|
||||
{
|
||||
Debug.WriteLine(string.Format(CultureInfo.InvariantCulture, "Thread {0}: DisableSource.", Thread.CurrentThread.ManagedThreadId));
|
||||
|
||||
rc = ((ITwainSessionInternal)this).DGControl.UserInterface.DisableDS(_twui);
|
||||
if (rc == ReturnCode.Success)
|
||||
_disabling = true;
|
||||
try
|
||||
{
|
||||
_callbackObj = null;
|
||||
SafeAsyncSyncableRaiseOnEvent(OnSourceDisabled, SourceDisabled);
|
||||
_msgLoopHook.Invoke(() =>
|
||||
{
|
||||
Debug.WriteLine(string.Format(CultureInfo.InvariantCulture, "Thread {0}: DisableSource.", Thread.CurrentThread.ManagedThreadId));
|
||||
|
||||
rc = ((ITwainSessionInternal)this).DGControl.UserInterface.DisableDS(_twui);
|
||||
if (rc == ReturnCode.Success)
|
||||
{
|
||||
_callbackObj = null;
|
||||
SafeAsyncSyncableRaiseOnEvent(OnSourceDisabled, SourceDisabled);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
finally
|
||||
{
|
||||
_disabling = false;
|
||||
}
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -788,6 +802,7 @@ namespace NTwain
|
||||
break;
|
||||
case Message.CloseDSReq:
|
||||
case Message.CloseDSOK:
|
||||
Debug.WriteLine("Got msg " + msg);
|
||||
// even though it says closeDS it's really disable.
|
||||
// dsok is sent if source is enabled with uionly
|
||||
|
||||
|
Reference in New Issue
Block a user