Вопрос

In my application, we can upload upload files to a server. For this I am using WININET. I want to stop the upload process when user click on Stop button. Now if the user click on stop button the ongoing process will not stop uploading. How can I deny the file from uploading.

Это было полезно?

Решение

If you are using WININET, you need to post the file in several smaller chunks. If the uses presses "Cancel" you then need to set a variable to abort the upload. This must be checked after each small upload... A full example of Splitting Uploads into smaller pparts can be found here: http://support.microsoft.com/kb/177188/en-us You need to download the "hsrex.exe" file and then open it with WinZip or 7-zip and extract the "BigPost.cpp" file. Also I can post the code here, if you want...

Другие советы

try CHttpFile::EndRequest() function...

Another idea, try to terminate the thread working for the upload operation

First, you need to be doing the WinInet stuff on a worker thread so that the UI is freed up to get the Cancel button click. When user clicks Cancel, your UI thread should close the handle being used by WinInet to upload chunks of the file. This causes WinInet to instantly abort any upload chunk currently in progress. To cleanly exit the worker thread at this point, the UI thread should set a bool 'done' flag that the worker thread reads, and if it is set, the worker thread exits instead of looping to upload another chunk.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top