Xamarinを使用してUIを更新するのが難しいです。目的は、ユーザーがアプリケーションが思考していることを知るように反応的なUIを作成することです。以下は私の試みです。XamarinでUIを更新する
試み1
private void BeginProcess(string fileName)
{
Device.BeginInvokeOnMainThread(() => {
iContent.Text = "UI Successfully updated.";
});
Device.BeginInvokeOnMainThread(() => {
ProccessFolder testMethod = new ProccessFolder.Initialize(fileName);
});
}
試み2
private void UpdateUI() {
iContent.Text = "UI Successfully updated.";
}
private void BeginProcess(string fileName)
{
System.Threading.Thread t = new System.Threading.Thread(UpdateUI);
t.Priority = System.Threading.ThreadPriority.Highest;
t.IsBackground = false;
t.Start();
Device.BeginInvokeOnMainThread(() => {
ProccessFolder testMethod = new ProccessFolder.Initialize(fileName);
});
}
試み3
private void BeginProcess(string fileName)
{
Device.BeginInvokeOnMainThread(() => {
iContent.Text = "UI Successfully updated.";
});
Task.Delay(5000);
Device.BeginInvokeOnMainThread(() => {
ProccessFolder testMethod = new ProccessFolder.Initialize(fileName);
});
}
残念ながらなしOこれらは機能します。私がProcessFolderメソッドをバックグラウンドスレッドに置き、メインスレッドのUI変更を呼び出すと、何ができますか?ただし、ProcessFolderメソッドの完了時間が遅くなります。
実行中にUIを更新する方法についてのご意見ProcessFolderメインスレッドでは?
InvokeOnMainThread()を試してください。アウェイは私のために働いた:); – burnsi
InvokeOnMainThreadの定義がデバイスに含まれていないと回答しました – RyeGuy
Xamarin.IOSを使用していますか?どのバージョン?私はデバイスを使用する必要はありません。他のオブジェクト参照なしでInvokeOnMainThread()を使用できます。 – burnsi