idhttp get 的时候界面卡死情况
小弟在用idhttp 从服务器 get 一个文件的时候,界面不能移动,卡的非常死,请问什么方法可以解决这个问题,网上有看 用AntiFreeze 来解决,但是貌似添了也无效。求教,下面是code 在线等。
//---------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------
#pragma package(smart_init)
#pragma link "CGAUGES"
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------
void __fastcall TForm1::IdHTTP1Work(TObject *Sender, TWorkMode AWorkMode,
const int AWorkCount)
{
CGauge1->Progress = AWorkCount;
}
//---------------------------------------
void __fastcall TForm1::IdHTTP1WorkBegin(TObject *Sender,
TWorkMode AWorkMode, const int AWorkCountMax)
{
Memo1->Lines->Add("Begin") ;
CGauge1->MaxValue = AWorkCountMax;
CGauge1->MinValue = 0;
CGauge1->Progress = 0;
}
//---------------------------------------
void __fastcall TForm1::IdHTTP1WorkEnd(TObject *Sender,
TWorkMode AWorkMode)
{
Memo1->Lines->Add("End");
}
//---------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
TStringStream *returnString=new TStringStream("");
Char* httpAddress = "http://unionupdate.kkpush.net/UnionUpdateService?";
Char* requestData = "param=<?xml%20version="1.0"%20encoding="utf-8"?><Request><RequestType>mobileVersion</RequestType><MobileVersionParams><OpType>getCurrentVersion</OpType><ClientVersion>";
Char* Version = "KABW960_CH.2.02.220";
Char* requestData2 = "</ClientVersion><RomSize></RomSize><UserName></UserName><SystemOuterVersion></SystemOuterVersion><FileType>img</FileType><CustomizationType>konka</CustomizationType>";
Char* requestData3 = "<Paramater1></Paramater1><Paramater2></Paramater2><Paramater3></Paramater3></MobileVersionParams><OtherParams></OtherParams></Request>";
StrCat(httpAddress,requestData);
StrCat(httpAddress,Version);
StrCat(httpAddress,requestData2);
StrCat(httpAddress,requestData3);
try
{
IdHTTP1->Get(httpAddress,returnString);
}
catch(...)
{
ShowMessage("服务器连接失败,请稍后重试");
this->Close();
}
String ss = returnString->DataString;
int i = ss.AnsiPos("KA"); /*获取最新的版本号,显示在Edit中*/
int j = ss.AnsiPos("</ResponseMessage>");
AnsiString version = ss.SubString(i,j-i);
int pos = ss.AnsiPos("http");/*获取最新版本的下载地址,进行下载*/
int end = ss.AnsiPos("</DownloadUrl>");
AnsiString http = ss.SubString(pos,end-pos);
delete returnString;
TMemoryStream *myStream = new TMemoryStream();
try
{
IdHTTP1->Get(http,myStream);
}
catch(...)
{
ShowMessage("服务器连接失败,请稍后重试");
return;
}
myStream->SaveToFile("C://update.zip");
delete myStream;
}
//---------------------------------------
void __fastcall TForm1::IdHTTP1Connected(TObject *Sender)
{
ShowMessage("connected");
}
//---------------------------------------
void __fastcall MyThread::Execute() {
Message msg;
while ( MsgQueue.GetMessage(&msg) ) {
switch ( msg.idType ) {
case MSG_EXIT :
goto exit;
case MSG_HTTP_REQ :
HttpSend((char*)msg.pvData);
break;
}
}
exit :
......
}
void MyThread::HttpSend(const char *szReq) {
....
http_get(....);
.....
}