Example #1
0
        public static void Update()
        {
            //init a new thread to refresh the game list
            if (!_started)
            {
                Task.Factory.StartNew(() => {
                    while (Global.RunState == RunState.Init)
                    {
                        var result = ApiReq.CreateReq()
                                     .WithMethod("api/Game", "get")
                                     .GetResult(out string json);
                        if (result == HttpStatusCode.OK)
                        {
                            dynamic array = DynamicJson.Parse(json);
                            if (array.IsArray)
                            {
                                lock (Games)
                                {
                                    Games.Clear();
                                    foreach (var item in array)
                                    {
                                        Games.Add(item);
                                    }
                                }
                            }
                        }

                        Thread.Sleep(2000);
                    }
                }).ContinueWith((task) => {
                    _started = false;
                });

                _started = true;
            }

            KeyboardHandler.Update();
        }
Example #2
0
        public static void Update()
        {
            //init a new thread to refresh the game list
            if (!_started)
            {
                Task.Factory.StartNew(() => {
                    while (Global.RunState == RunState.Run)
                    {
                        string url = "api/Game/" + _game.id.ToString();
                        var result = ApiReq.CreateReq()
                                     .WithMethod(url, "get")
                                     .GetResult(out string json);
                        if (result == HttpStatusCode.OK)
                        {
                            dynamic data = DynamicJson.Parse(json);
                            if (json != "{}")
                            {
                                LoadGameData(data);
                            }

                            if (_state > 1)
                            {
                                break;
                            }
                        }

                        Thread.Sleep(1000);
                    }
                }).ContinueWith((task) => {
                    _started = false;
                });

                _started = true;
            }

            KeyboardHandler.Update();
        }