检测uploadValues何时完成?

时间:2014-06-25 17:44:14

标签: c# php

我希望在将数据发布到远程php文件后显示一个消息框。

PS:php文件返回字符串" END"数据完全处理后

if (1 == outputToGui)
{
    CompressFile("allFilesList.txt");

    byte[] allFilesList = File.ReadAllBytes("allFilesList.txt.gz");
    string URIx = "http://example.com/post.php";
    System.Collections.Specialized.NameValueCollection data = new System.Collections.Specialized.NameValueCollection();
    data.Add("serial", serial);
    data.Add("data", Convert.ToBase64String(allFilesList));
    using (WebClient tayba = new System.Net.WebClient())
    {
        try
        {
            tayba.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
            tayba.Proxy = null;
            tayba.UploadValues(URIx, "POST", data);
        }
        catch (Exception E) { }
    }
}
MessageBox.Show("upload completed"); // this message show up before the php file process the posted data sometimes.. ?!!!!

问题是消息框有时会在php文件处理发布的数据之前显示..?!!!!

1 个答案:

答案 0 :(得分:0)

那是因为操作是异步的。调用messagebox时,上载可能仍在进行中。

搜索webclient以获取正确的完成事件,并在那里添加您的消息。 META:_webClient.eventName + =(sender,args)=> MessageBox.Show( “钽大新!”);

在开始上传之前分配事件侦听器。

相关问题