您好,我正在尝试通过 c# 将文件上传到我的网络服务器,并且在上传文件时遇到问题,我的应用程序冻结,直到文件上传完成,我想上传它异步但我似乎无法获取代码在这里工作是有代码和我不断收到的错误。
此代码有效,但冻结了表单。
WebClient wc = new WebClient();
wc.Credentials = new System.Net.NetworkCredential(TxtUsername.Text, TxtPassword.Text);
string Filename = TxtFilename.Text;
string Server = TxtServer.Text + SafeFileName.Text;
wc.UploadFile(Server, Filename);
但是,如果我执行此代码,则会出现错误。
WebClient wc = new WebClient();
wc.Credentials = new System.Net.NetworkCredential(TxtUsername.Text, TxtPassword.Text);
string Filename = TxtFilename.Text;
string Server = TxtServer.Text + SafeFileName.Text;
wc.UploadFileAsync(Server, Filename);
尝试使其异步时出现此错误
Error 1 The best overloaded method match for System.Net.WebClient.UploadFileAsync(System.Uri, string)' has some invalid arguments.
Error 2 Argument 1: cannot convert from 'string' to 'System.Uri'