Queued file transfers are performed asynchronously using a
background worker thread. If you provide the address to an event
callback function, that method will always be invoked in the context
of the queue manager thread. You must ensure that any access to global
or static variables are synchronized, otherwise the results may be
unpredictable. It is recommended that you do not declare any static
variables within the callback function itself and you should avoid
calling any methods which could cause the thread to block. For
example, you should not attempt to establish other network connections
from within the event handler.
If your application has a graphical user interface, you should never
attempt to directly modify a UI control from within the callback
method. Controls should only be modified by the same UI thread that
created their window. One common approach to address this issue is to
post a user-defined message to the main window to signal that the user
interface needs to be updated. The message handler would then process
the user-defined message and update the user interface as needed.
The callback function specified by the lpEventProc
parameter must be declared using the __stdcall
calling convention. This ensures the arguments passed to the event
handler are pushed on to the stack in the correct order. Failure to
use the correct calling convention will corrupt the stack and cause
the application to terminate abnormally.
The dwParam parameter is commonly used to identify the
class instance which is associated with the event that has occurred.
Applications will cast the this pointer to a
DWORD_PTR value when calling this function, and then the event handler
will cast it back to a pointer to the class instance. This gives the
handler access to the class member variables and methods.
The Wait method can be used to wait for the
queue manager to complete processing the transfer queue.