我是WP8编程的新手,我不知道如何调用异步方法并更新我的UI。基本上这是我的例子:
public class MyClassGetFinishedEventArgs : EventArgs
{
public MyClass SomeObject{ get; set; }
public List<MyClass> SomeList{ get; set; }
}
public static class MyClassManager
{
private static MyClassService service = new MyClassService();
public static event EventHandler GetFinished = delegate { };
static MyClassManager()
{
service = new MyClassService();
}
public static void Get()
{
var ea = new MyClassGetFinishedEventArgs();
service.Get(
delegate {
ea.SomeList = service.SomeList;
GetFinished(null, ea);
}
);
}
}
在Android上我按这样打电话:
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.frmContent);
MyClassManager.GetFinished += HandleFinishedGet;
MyClassManager.Get();
}
void HandleFinishedGet(object sender, EventArgs ea)
{
var args = ea as GetFinishedEventArgs;
if (args != null)
{
if (args.Success)
{
act.RunOnUiThread(() =>
{
//Do something to update UI
}
);
}
}
}
有没有办法在Windows Phone中执行相同操作?
答案 0 :(得分:0)
你试过吗
Deployment.Current.Dispatcher.BeginInvoke(() =>
{
//update UI?
});