小编mih*_*123的帖子

将参数传递给WebClient.DownloadFileCompleted事件

我正在使用该WebClient.DownloadFileAsync()方法,并想知道如何将参数传递给WebClient.DownloadFileCompleted事件(或任何其他事件),并在调用的方法中使用它.

我的代码:

public class MyClass
{
    string downloadPath = "some_path";
    void DownloadFile()
    {
        int fileNameID = 10;
        WebClient webClient = new WebClient();
        webClient.DownloadFileCompleted += DoSomethingOnFinish;
        Uri uri = new Uri(downloadPath + "\" + fileNameID );
        webClient.DownloadFileAsync(uri,ApplicationSettings.GetBaseFilesPath +"\" + fileNameID); 
    }

    void DoSomethingOnFinish(object sender, AsyncCompletedEventArgs e)
    {
        //How can i use fileNameID's value here?
    }

}
Run Code Online (Sandbox Code Playgroud)

如何将参数传递给DoSomethingOnFinish()

c# asynchronous unity-game-engine unity5

3
推荐指数
1
解决办法
3027
查看次数

标签 统计

asynchronous ×1

c# ×1

unity-game-engine ×1

unity5 ×1