not using while(true) equals in much frustration

This commit is contained in:
Yorick Rommers
2016-01-19 18:59:42 +01:00
parent 727e3212c6
commit b8a1261600
2 changed files with 8 additions and 8 deletions
+4 -2
View File
@@ -20,6 +20,7 @@ namespace YJMPD_UWP.Model
Hi,
Name,
Picture,
Msg,
GameFound,
PlayerJoined
}
@@ -31,6 +32,7 @@ namespace YJMPD_UWP.Model
public void HandleMessage(JObject o)
{
Debug.WriteLine("Reached HandleMessage in API");
Command c = (Command)Enum.Parse(typeof(Command), o["command"].ToString());
switch(c)
@@ -39,7 +41,8 @@ namespace YJMPD_UWP.Model
GameFound();
break;
case Command.PlayerJoined:
PlayerJoined(o["msg"].ToString());
Debug.WriteLine("Played joined");
PlayerJoined(o[Command.PlayerJoined.ToString()].ToString());
break;
default:
//Do nothing
@@ -50,7 +53,6 @@ namespace YJMPD_UWP.Model
private void PlayerJoined(string username)
{
throw new NotImplementedException();
//Event will be handled by the game manager
App.Game.AddPlayer(username);
}
+4 -6
View File
@@ -83,12 +83,12 @@ namespace YJMPD_UWP.Model
BackgroundReader = Windows.System.Threading.ThreadPool.RunAsync(async (workItem) =>
{
while (workItem.Status == AsyncStatus.Started)
while (true)
{
Debug.WriteLine("Awaiting incoming data...");
string data = await App.Network.Read();
App.Network.HandleMessage(data);
Task.Delay(TimeSpan.FromMilliseconds(50));
await Task.Delay(TimeSpan.FromMilliseconds(50));
}
});
@@ -114,10 +114,8 @@ namespace YJMPD_UWP.Model
{
Debug.WriteLine(data);
JObject o = JObject.Parse(data);
if (o["msg"].ToString() == "ok")
{
App.Api.HandleMessage(o);
}
App.Api.HandleMessage(o);
}
}
}