Asynchronous Notes

FTPv2.ahk / oFTP

Asynchronous mode notes



1. You can only make one asynchronous mode connection at a time at present.

2. Functions which use data buffers will not work in asynchronous mode.
(Not because it is not possible in AHK, but because it is not desirable* and beyond my skill level)

These functions include:
 - .GetCurrentDirectory()
 - .FindFirstFile / .FindNextFile
 - .InternetReadFile / .InternetWriteFile

Ref: http://support.microsoft.com/kb/189850 -> INFO: Using WinInet APIs Asynchronously Within Visual Basic
To quote the last line of the said article:
"This makes using WinInet APIs in Visual Basic asynchronously an undesirable option."

3. Default Async callback function logs all output to stdout
The default async callback function logs all output to stdout, so it can be only seen if debugger attached or you run it with Scite4Autohotkey.

4. The script can continue doing other tasks while waiting for async request complete notification.

5. Callback function:
Note that you can specify the function to call (AsyncMode parameter can be the name of the function). Because callbacks are made during processing of the request, the application should spend little time in the callback function to avoid degrading data throughput on the network. For example, displaying a msgbox in a callback function can be such a lengthy operation that the server terminates the request.

6. Memory/File operations:
In your script, please do not write to the memory/file that has set up to use in the callback function. Both the script and wininet callback may try to write to the same memory location/file and corrupt the file/memory or crash the script.

7. AHK and multithreading:
As AHK uses psuedo-multithreading (it is a single thread only), wininet callbacks will pause the currently executing thread. If the current executing thread is critical, the async notifications may be missed.