When developing an online game client, we often open a thread to receive and send network messages. At this time, we will inevitably encounter some problems, such: players can be online or offline in some battle lists at any time. In this case, we should involve the synchronization problem between the UI thread (main thread) and network thread: If you directly obtain data in the network thread, you can use it directly.
When developing an online game client, we often open a thread to receive and send network messages. At this time, we will inevitably encounter some problems, such: players can be online or offline in some battle lists at any time. In this case, we should involve the synchronization problem between the UI thread (main thread) and network thread: If you directly obtain data in the network thread, you can use it directly.
When developing an online game client, we often open a thread to receive and send network messages. At this time, we will inevitably encounter some problems, such:
Players can be online or offline in some battle lists at any time. At this time, we should be involved in the synchronization of the UI thread (main thread) and network thread:
If you directly use the data obtained in the network thread, there will certainly be various strange problems. So a common practice is:
Use a variable to judge: m_bFresh
Void UserList: visit (void)
{
CCLayer: visit ();
If (m_bFresh ){
UpDataUserList ();
}
M_bInGame = true;
}
Because visit will always be called, you just need to click it to refresh it.
Void UserList: upDataUserList ()
{
M_pUserList = NET_MANAGER-> getUserList (); this is the latest data.
M_pTableView-> reloadData ();
M_bFresh =! M_bFresh;
}