之前寫了個測試程式來測一下sandbox程式,
卻發現偶而會hang.
直接不在sandbox裡執行,
還是偶而會hang.
看來是跟OS系統有關,
就逐步把多餘的code移除掉,
剩下create a new thread, suspend the thread,
resume the thread, 然後 terminate the thread,
再call URLDownloadToFileA.
這樣的組合就偶而會造成整個程式hang住.
在win7下測試過, 似乎就是不會發生.
但在win10下就是偶而會整個hang住, 原因不明.
程式碼如下:
#include <stdio.h>
#include <winsock2.h>
#include <urlmon.h>
#include <Psapi.h>
#include <Windows.h>
DWORD WINAPI MyThreadFunction(LPVOID lpParam)
{
while (1);
return 0;
}
int main()
{
if (1) {
HANDLE hThread = CreateThread(
NULL, // default security attributes
0, // use default stack size
MyThreadFunction, // thread function name
NULL, // argument to thread function
0, // use default creation flags
NULL); // returns the thread identifier
SuspendThread(hThread);
ResumeThread(hThread);
TerminateThread(hThread, 0);
}
if (1) {
HRESULT res;
char url[] = "http://www.google.com/";
char path[] = "c:\\temp\\index.html";
// printf("URLDownloadToFileA\n");
res = URLDownloadToFileA(NULL, url, path, 0, NULL);
}
return 0;
}