我包括UIActivityIndicator
在我的UIViewController
。我需要从FTP使用一个文件。
我的按钮上有一个按钮ViewController
,单击该按钮后,下载将开始。我在UIActivityIndicator
(aiReceive
)上放了一个()ViewController
,它在视图控制器上以停止状态显示,但只有在完成文件下载后才能进行动画处理。
我正在Xamarin IOS中制作iPad App。
我添加了异步方法,但是现在出现以下错误。仅当其包含的lambda表达式用async修饰符标记时,才可以使用await运算符
public partial class FirstViewController : UIViewController
{
public override void ViewDidLoad()
{
base.ViewDidLoad();
btnReceiveData.TouchUpInside += (object sender, EventArgs e) =>
{
//BTProgressHUD.Show("Receiving Data..."); --> This Component is also not working,
aiReceive.StartAnimating();
await GetFileAsync());
BTProgressHUD.Dismiss();
};
}
async Task GetFileAsync()
{
using (var client = new HttpClient())
{
try
{
aiReceive.StartAnimating(); /* --> Inimation is not starting at this point. Animation Start After Downloading file, download takes time, i want to show animation in the mean while.*/
using (WebClient ftpclient = new WebClient())
{
try
{
ftpclient.Credentials = new System.Net.NetworkCredential("UserName", "Password");
string sourceFilePath = @"ftp://ftp.google.com/FileName.pdf";
var FileDownloadStart = UIAlertController.Create("Info", "Data file received.", UIAlertControllerStyle.Alert);
FileDownloadStart.AddAction(UIAlertAction.Create("Ok", UIAlertActionStyle.Default, null));
UIApplication.SharedApplication.KeyWindow.RootViewController.PresentViewController(FileDownloadStart, true, null);
//Downloading file from FTP.
ftpclient.DownloadFile(sourceFilePath, "C:\");
var FileDownloadAlert = UIAlertController.Create("Info", "Data file received.", UIAlertControllerStyle.Alert);
FileDownloadAlert.AddAction(UIAlertAction.Create("Ok", UIAlertActionStyle.Default, null));
UIApplication.SharedApplication.KeyWindow.RootViewController.PresentViewController(FileDownloadAlert, true, null);
}
catch (Exception ex)
{
File.Delete(EpazzDirectory + AuditorId.ToString());
var ExceptionAlert = UIAlertController.Create("Exception", ex.Message, UIAlertControllerStyle.Alert);
ExceptionAlert.AddAction(UIAlertAction.Create("Ok", UIAlertActionStyle.Default, null));
UIApplication.SharedApplication.KeyWindow.RootViewController.PresentViewController(ExceptionAlert, true, null);
}
}
}
}
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句