나는 포함하고 있습니다 UIActivityIndicator
내에서 UIViewController
. FTP에서 파일을 가져와야합니다.
내에 버튼이 있습니다. 해당 버튼을 ViewController
클릭하면 다운로드가 시작됩니다. 내가 넣어 UIActivityIndicator
( aiReceive
) 내에서 ViewController
파일 다운로드 완료시에만 애니메이션 내보기 컨트롤러, 즉 정지 된 상태에서 나타나고있다, 그러나.
Xamarin IOS에서 iPad 앱을 만들고 있습니다.
비동기 메서드를 추가했지만 지금 아래 오류가 발생합니다. await 연산자는 포함 된 람다식이 async 한정자로 표시된 경우에만 사용할 수 있습니다.
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);
}
}
}
}
}
}
UI 스레드를 차단하고 있으므로 UI에 적용하려는 변경 사항이 적용되지 않습니다 (이 경우 UIActivityIndicator
애니메이션 회전).
이를 수행하는 가장 좋은 방법은 다음과 같이 async / await를 사용하는 것입니다.
aiReceive.StartAnimating();
await YourFTPRequestAsync();
aiReceive.StopAnimating();
다음은 async \ await에 대한 공식 MSDN 문서 와 작동 방식에 대한 샘플 기반 힌트 입니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다