Microsoft KB Archive/164983

= How To Do Asynchronous WinInet with MFC Classes =

Article ID: 164983

Article Last Modified on 7/1/2004

-

APPLIES TO


 * Microsoft Visual C++ 5.0 Enterprise Edition
 * Microsoft Visual C++ 6.0 Enterprise Edition
 * Microsoft Visual C++ 5.0 Professional Edition
 * Microsoft Visual C++ 6.0 Professional Edition
 * Microsoft Visual C++ 6.0 Standard Edition
 * Microsoft Internet Explorer 4.0 128-Bit Edition
 * Microsoft Windows Internet Services (WinInet)

-



This article was previously published under Q164983



SUMMARY
The MFC WinInet classes (CInternetSession, CInternetConnection, and so forth) are not designed to be used with asynchronous WinInet connections or file transfer. Instead, developers looking for asynchronous-like behavior in their MFC WinInet application should implement separate synchronous WinInet sessions in secondary threads.



MORE INFORMATION
A WinInet application creates an asynchronous WinInet session by using INTERNET_FLAG_ASYNC in the last parameter of the CInternetSession constructor, dwFlags.

Because some Internet operations may take a long period of time to complete, it is often desirable to make asynchronous WinInet calls, which return control to the application and run the operation in the background. This allows the application's user interface to continue to function. In addition, the application can display status updates on a lengthy download or even allow the user to halt an operation while it is executing. In this case, the recommended method for an MFC WinInet application is to not use INTERNET_FLAG_ASYNC in constructing the CInternetSession. Instead, for each necessary concurrent session, a secondary thread is spawned from the main thread. Each secondary thread is responsible for creating a new CInternetSession object without the INTERNET_FLAG_ASYNC flag and then performing any needed operations on that synchronous session, such as making an FTP connection and then downloading a file.

In some cases however, true asynchronous WinInet is really the desired goal. If this is the case, developers are encouraged to abandon their use of the MFC WinInet classes and make calls to the WinInet API directly. You can get more information about this from the Internet Client SDK at:

http://www.microsoft.com/msdn/sdk/inetsdk/help/default.htm

Keywords: kbhowto KB164983

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.