I have a MFC application where it tries to get a page using cURL. When running the app, the dialog becomes unresponsive for a moment. Is there any way to fix this?
static size_t WriteCallback(void *contents, size_t size, size_t nmemb, void *userp)
{
((std::string*)userp)->append((char*)contents, size * nmemb);
return size * nmemb;
}
static std::string GetPage(const char* url)
{
CURL *curl;
CURLcode res;
std::string page;
curl = curl_easy_init();
if (curl) {
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &page);
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
return page;
}
InitInstance():
CWinApp::InitInstance();
CEpicDlg dlg;
m_pMainWnd = &dlg;
dlg.Create(IDD_MAIN);
dlg.ShowWindow(SW_SHOW);
GetPage("http://example.com/page");
dlg.RunModalLoop(MLF_NOIDLEMSG);
GetPage("http://example.com/page");on a worker thread, then post its results to show them in dialog on GUI thread. - marcinj