We have a situation where we use the WebClient class to download some data from a server. We have control over both the client and server portions. Currently, each time a user does an action, a webclient is generated and used to make a connection to a server. The client then downloads some data in the background and does some work with it. The problem arises when the user causes this to happen repeatedly… On the server side (NOT .net based!) we see that the connection times out after our timeout period and not teardown is ever sent to the server. This brings me to my question…
Is there a proper way to signal or force a teardown of the HTTP connection used by the webclient class?
Code:
pMPTF is a callback class to bring the .net event into the unmanaged world.
void Callback(System::Object^ sender, System::Net::DownloadDataCompletedEventArgs^ e)
{
WebClient^ w = (WebClient^)sender;
w->Dispose();
if( e->Error == nullptr && pMPTF != NULL )
pMPTF->ParseResponse(e->Result);
else
pMPTF->ParseResponse( nullptr );
}
Gives:
error C2039: ‘Dispose’ : is not a member of ‘System::Net::WebClient’
The operation is completed at that point. If use
deletethe object will be disposed. I would recommend reading-up on how objects are disposed in managed C++: msdn.microsoft.com/en-us/library/ms177197.aspxIf you want to manually close the response, you can call
GetWebResponseand call theCloseon the returnedWebResponseobject.