7,540
社区成员
发帖
与我相关
我的任务
分享
void DownloadDataInBackground(String^ address, String^ dataTemp)
{
try
{
WebClient^ client = gcnew WebClient;
client->BaseAddress = address;
client->DownloadDataCompleted += gcnew DownloadDataCompletedEventHandler(DownloadDataCallback);
client->DownloadDataAsync(gcnew Uri(address));
}
catch(...)
{
Console::WriteLine("{0} download failed!", address);
}
}
其中,address是下载地址,dataTemp是我要传递的数据。ref class myWebClient : WebClient
{
public:
myWebClient()
{
}
String ^ dataTemp;
};
这样,在回调函数里就可以这样(myWebClient^)sender->dataTemp获取到我要传的参数了!
不知道这样做有啥坏的影响不,求简单而安全的方法?!