mirror of
https://github.com/soukoku/ntwain.git
synced 2026-02-25 13:04:07 +08:00
Merge pull request #71 from SteffenSH/v4-fixed-DetatchAsync
Fix: CloseDSMAsync() hang in TwainAppSession
This commit is contained in:
@@ -69,12 +69,12 @@ namespace NTwain
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Detatches a previously attached session and stops the thread.
|
/// Detatches a previously attached session and stops the thread.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public async Task<STS> DetatchAsync()
|
public async Task<STS> DetachAsync()
|
||||||
{
|
{
|
||||||
STS sts = default;
|
STS sts = default;
|
||||||
if (_dummyForm != null && _twain != null)
|
if (_dummyForm != null && _twain != null)
|
||||||
{
|
{
|
||||||
TaskCompletionSource<bool> tcs = new();
|
TaskCompletionSource<STS> tcs = new();
|
||||||
_dummyForm.BeginInvoke(() =>
|
_dummyForm.BeginInvoke(() =>
|
||||||
{
|
{
|
||||||
sts = _twain.CloseDSMReal();
|
sts = _twain.CloseDSMReal();
|
||||||
@@ -84,6 +84,7 @@ namespace NTwain
|
|||||||
_dummyForm.Close();
|
_dummyForm.Close();
|
||||||
_twain = null;
|
_twain = null;
|
||||||
}
|
}
|
||||||
|
tcs.SetResult(sts);
|
||||||
});
|
});
|
||||||
await tcs.Task;
|
await tcs.Task;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -144,7 +144,7 @@ namespace NTwain
|
|||||||
{
|
{
|
||||||
if (_selfPump == null) throw new InvalidOperationException($"Cannot close if not opened with {nameof(OpenDSMAsync)}().");
|
if (_selfPump == null) throw new InvalidOperationException($"Cannot close if not opened with {nameof(OpenDSMAsync)}().");
|
||||||
|
|
||||||
var sts = await _selfPump.DetatchAsync();
|
var sts = await _selfPump.DetachAsync();
|
||||||
if (sts.IsSuccess)
|
if (sts.IsSuccess)
|
||||||
{
|
{
|
||||||
_selfPump = null;
|
_selfPump = null;
|
||||||
|
|||||||
Reference in New Issue
Block a user