Some fixes for bad sources.

This commit is contained in:
Eugene Wang
2023-04-09 22:35:15 -04:00
parent 64268b3a27
commit 3d82558af6
2 changed files with 17 additions and 3 deletions

View File

@@ -87,6 +87,7 @@ namespace NTwain
}
bool _closeDsRequested;
bool _inTransfer;
private void HandleSourceMsg(MSG msg, [CallerMemberName] string? caller = null)
{
@@ -95,16 +96,27 @@ namespace NTwain
// the reason we post these to the background is
// if they're coming from UI message loop then
// this needs to return asap (?)
switch (msg)
{
case MSG.XFERREADY:
// some sources spam this even during transfer so we gate it
if (!_inTransfer)
{
_inTransfer = true;
_bgPendingMsgs.Add(msg);
}
break;
case MSG.DEVICEEVENT:
case MSG.CLOSEDSOK:
_bgPendingMsgs.Add(msg);
break;
case MSG.CLOSEDSREQ:
_closeDsRequested = true;
_bgPendingMsgs.Add(msg);
if (!_inTransfer)
{
_bgPendingMsgs.Add(msg);
}
break;
}
}

View File

@@ -171,7 +171,7 @@ namespace NTwain
}
HandleXferCode(sts);
_inTransfer = false;
if (State >= STATE.S5)
{
_uiThreadMarshaller.BeginInvoke(() =>
@@ -491,6 +491,7 @@ namespace NTwain
IntPtr lockedPtr = IntPtr.Zero;
try
{
DGImage.ImageInfo.Get(ref _appIdentity, ref _currentDS, out TW_IMAGEINFO info);
var sts = WrapInSTS(DGImage.ImageNativeXfer.Get(ref _appIdentity, ref _currentDS, out dataPtr));
if (sts.RC == TWRC.XFERDONE)
{
@@ -516,7 +517,8 @@ namespace NTwain
{
try
{
DGImage.ImageInfo.Get(ref _appIdentity, ref _currentDS, out TW_IMAGEINFO info);
// some sources do not support getting image info in state 7 so
// it's up there in the beginning now.
var args = new TransferredEventArgs(this, info, null, data);
Transferred?.Invoke(this, args);
}