mirror of
https://github.com/soukoku/ntwain.git
synced 2025-04-05 20:59:23 +08:00
Changed ManualResetEventSlim to TaskCompletionSource in pump thread attach.
This commit is contained in:
parent
54d73eb42c
commit
0e5aef00e5
@ -38,22 +38,32 @@ namespace NTwain
|
||||
|
||||
while (_dummyForm == null || !_dummyForm.IsHandleCreated)
|
||||
{
|
||||
await Task.Delay(100);
|
||||
await Task.Delay(50);
|
||||
}
|
||||
|
||||
STS sts = default;
|
||||
ManualResetEventSlim evt = new();
|
||||
TaskCompletionSource<bool> tcs = new();
|
||||
_dummyForm.BeginInvoke(() =>
|
||||
{
|
||||
sts = twain.OpenDSM(_dummyForm.Handle, SynchronizationContext.Current!);
|
||||
if (sts.IsSuccess)
|
||||
try
|
||||
{
|
||||
twain.AddWinformFilter();
|
||||
_twain = twain;
|
||||
sts = twain.OpenDSM(_dummyForm.Handle, SynchronizationContext.Current!);
|
||||
if (sts.IsSuccess)
|
||||
{
|
||||
twain.AddWinformFilter();
|
||||
_twain = twain;
|
||||
}
|
||||
else
|
||||
{
|
||||
_dummyForm.Close();
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
tcs.TrySetResult(true);
|
||||
}
|
||||
evt.Set();
|
||||
});
|
||||
evt.Wait();
|
||||
await tcs.Task;
|
||||
return sts;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user