mirror of
https://github.com/soukoku/ntwain.git
synced 2025-04-05 20:59:23 +08:00
More tweaks on when to disable source.
This commit is contained in:
parent
b603dd7f59
commit
42cbd75765
src/NTwain
@ -46,6 +46,8 @@ namespace NTwain.Internals
|
||||
|
||||
ReturnCode EnableSource(SourceEnableMode mode, bool modal, IntPtr windowHandle);
|
||||
|
||||
bool CloseDSRequested { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the triplet operations defined for audio data group.
|
||||
/// </summary>
|
||||
|
@ -58,7 +58,7 @@ namespace NTwain.Internals
|
||||
|
||||
#region actually handle xfer
|
||||
|
||||
if (preXferArgs.CancelAll)
|
||||
if (preXferArgs.CancelAll || session.CloseDSRequested)
|
||||
{
|
||||
rc = session.DGControl.PendingXfers.Reset(pending);
|
||||
}
|
||||
@ -99,21 +99,11 @@ namespace NTwain.Internals
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
switch (rc)
|
||||
{
|
||||
case ReturnCode.Cancel:
|
||||
default:
|
||||
// as usual
|
||||
rc = session.DGControl.PendingXfers.EndXfer(pending);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if (rc != ReturnCode.Success && session.StopOnTransferError)
|
||||
{
|
||||
// end xfer without setting rc to exit (good/bad?)
|
||||
session.DGControl.PendingXfers.EndXfer(pending);
|
||||
session.DGControl.PendingXfers.Reset(pending);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -122,7 +112,7 @@ namespace NTwain.Internals
|
||||
}
|
||||
#endregion
|
||||
|
||||
} while (rc == ReturnCode.Success && pending.Count != 0);
|
||||
} while (rc == ReturnCode.Success && pending.Count != 0 && !session.CloseDSRequested);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -131,7 +121,8 @@ namespace NTwain.Internals
|
||||
|
||||
// some poorly written scanner drivers return failure on EndXfer so also check for pending count now.
|
||||
// this may break with other sources but we'll see
|
||||
if (pending.Count == 0 && session.State > 5)
|
||||
if (//pending.Count == 0 &&
|
||||
session.State > 5)
|
||||
{
|
||||
session.ChangeState(5, true);
|
||||
session.DisableSource();
|
||||
|
@ -23,7 +23,7 @@ namespace NTwain
|
||||
/// <summary>
|
||||
/// The build release version number.
|
||||
/// </summary>
|
||||
public const string Build = "3.3.9"; // change this for each nuget release
|
||||
public const string Build = "3.3.9.2"; // change this for each nuget release
|
||||
|
||||
|
||||
}
|
||||
|
@ -393,11 +393,30 @@ namespace NTwain
|
||||
{
|
||||
if (targetState < 7 && CurrentSource != null)
|
||||
{
|
||||
((ITwainSessionInternal)this).DGControl.PendingXfers.EndXfer(new TWPendingXfers());
|
||||
// not sure if really necessary but can't hurt to pin it
|
||||
var pending = new TWPendingXfers();
|
||||
var handle = GCHandle.Alloc(pending, GCHandleType.Pinned);
|
||||
try
|
||||
{
|
||||
((ITwainSessionInternal)this).DGControl.PendingXfers.EndXfer(pending);
|
||||
}
|
||||
finally
|
||||
{
|
||||
handle.Free();
|
||||
}
|
||||
}
|
||||
if (targetState < 6 && CurrentSource != null)
|
||||
{
|
||||
((ITwainSessionInternal)this).DGControl.PendingXfers.Reset(new TWPendingXfers());
|
||||
var pending = new TWPendingXfers();
|
||||
var handle = GCHandle.Alloc(pending, GCHandleType.Pinned);
|
||||
try
|
||||
{
|
||||
((ITwainSessionInternal)this).DGControl.PendingXfers.Reset(pending);
|
||||
}
|
||||
finally
|
||||
{
|
||||
handle.Free();
|
||||
}
|
||||
}
|
||||
if (targetState < 5 && CurrentSource != null)
|
||||
{
|
||||
|
@ -28,6 +28,9 @@ namespace NTwain
|
||||
/// <value>The app id.</value>
|
||||
TWIdentity ITwainSessionInternal.AppId { get { return _appId; } }
|
||||
|
||||
bool _closeRequested;
|
||||
bool ITwainSessionInternal.CloseDSRequested { get { return _closeRequested; } }
|
||||
|
||||
void ITwainSessionInternal.UpdateCallback()
|
||||
{
|
||||
if (State < 4)
|
||||
@ -155,6 +158,7 @@ namespace NTwain
|
||||
/// <returns></returns>
|
||||
ReturnCode ITwainSessionInternal.EnableSource(SourceEnableMode mode, bool modal, IntPtr windowHandle)
|
||||
{
|
||||
_closeRequested = false;
|
||||
var rc = ReturnCode.Failure;
|
||||
|
||||
_msgLoopHook.Invoke(() =>
|
||||
@ -308,7 +312,9 @@ namespace NTwain
|
||||
// some sources send this at other states so do a step down
|
||||
if (State > 5)
|
||||
{
|
||||
ForceStepDown(4);
|
||||
// rather than do a close here let the transfer logic handle the close down now
|
||||
//ForceStepDown(4);
|
||||
_closeRequested = true;
|
||||
}
|
||||
else if (State == 5)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user