dynarithmic / twain_library

Dynarithmic TWAIN Library, Version 5.x
Apache License 2.0
56 stars 24 forks source link

Is the DTWAIN_AcquireFile api async or sync function? #70

Closed madeline799 closed 9 months ago

madeline799 commented 1 year ago

if DTWAIN_AcquireFile is sync api,how to work for a async function?

dynarithmic commented 1 year ago

Please note that DTWAIN is limited to what TWAIN does during the acquisition processing. There are messages being sent from the TWAIN driver back to DTWAIN during processing -- DTWAIN has no control over this, as this is part of how TWAIN works internally. The TWAIN specification dates back to the early 1990's, thus there was no real distinction at that time between "async" and "sync". Everything was done assuming one thread of execution running the acquisition.

Having said this, there is a message loop being run when the acquisition process is occuring. Thus there are two ways that DTWAIN_AcquireFile (and any other DTWAIN_Acquire... function) works:

1) modal, where the DTWAIN_AcquireFile is blocked (the call to DTWAIN_AcquireFile does not return until acquisition is done), or

2) modeless, where the DTWAIN_Acquire function is not blocked, but your application is responsible to implement the message loop (DTWAIN_AcquireFile returns immediately, and your application must then implement the message loop).

So you have one of two choices -- modal or modeless. Note that you can also have notifications being sent to a custom notification function during processing.

Sorry if this doesn't completely answer your questions, but these are the options you have.