private void Awake() { State = (CheckIfTheIngredientsInInventoryAreCompatible()) ? CookingStationState.AVAILABLE : CookingStationState.NOT_VISIBLE_TO_LOCAL_PLAYER; _CookingStationUI = GetComponentInChildren <CookingStationUI>(); _Animator = GetComponent <Animator>(); _Clock = GetComponentInChildren <CircularProgressbar>(true); }
/** * <summary>Start ping thread if not alive.</summary> **/ public void StartPing(CircularProgressbar bar) { this.bar = bar; if (pingThread == null) { pingThread = new Thread(new ParameterizedThreadStart(Process.GetPing)); pingThread.Start(new object[] { Process.IPServerAPI, bar, this }); runningThreads.Add(pingThread); } }
public static void GetPing(object args) { object[] obj = (object[])args; string ip = (string)obj.GetValue(0); CircularProgressbar bar = (CircularProgressbar)obj.GetValue(1); PerformanceTracker tracker = (PerformanceTracker)obj.GetValue(2); while (true) { Ping ping = new Ping(); PingOptions options = new PingOptions { DontFragment = true }; string data = "aaaaaaaaaaaaaaaaaaaa"; byte[] buffer = Encoding.ASCII.GetBytes(data); PingReply reply = null; try { reply = ping.Send(ip, 120, buffer, options); if (reply.Status == IPStatus.Success) { bar.Dispatcher.Invoke( new PerformanceTracker.UpdatePingCallback(tracker.UpdatePing), unchecked ((int)reply.RoundtripTime) ); } Thread.Sleep(1000); } catch (Exception e) { Console.WriteLine(e); Thread.CurrentThread.Abort(); } } }