我有一个事件处理程序,在事件onLobbyParticipantAdded
到达后调用方法(lobbyParicipantAdded
)。
在方法onLobbyPaticipantAdded
中,如果想要在UI中更改内容,它总是会结束。
这是我的代码
public override void ViewDidLoad()
{
base.ViewDidLoad();
EventHandler.Add("lobbyParticipantAdded", onLobbyParticipantAdded);
}
public void onLobbyParticipantAdded(dynamic obj)
{
LobbyParticipantAdded l = new LobbyParticipantAdded();
l = obj;
SC1.Text = l.displayname;
Ready1.Text = "Ready";
}
有人知道这个问题吗?并知道如何解决它?
答案 0 :(得分:2)
您需要在主线程中执行与UI相关的代码(如下例所示)
public void onLobbyParticipantAdded(dynamic obj)
{
LobbyParticipantAdded l = new LobbyParticipantAdded();
l = obj;
this.InvokeOnMainThread (() =>
{
SC1.Text = l.displayname;
Ready1.Text = "Ready";
});
}