internal static StopWatch StartNew() { StopWatch stopWatch = new StopWatch(); stopWatch.Start(); return stopWatch; }
private static void ThreadMethodSendATCommands() { string commandBatch = null; Socket socket = UdpSockets[CommunicationChannel.Command]; IPEndPoint endPoint = new IPEndPoint(IPAddress.Any, 0); StopWatch stopWatch = new StopWatch(); do { try { stopWatch.Restart(); if (!DroneProxy.IsInitialized) { InitializeDrone(); } commandBatch = CommandCenter.GetNextCommandBatch(); //Simple way to be able to only view the commands that would be sent and not //actually send them. Maybe to be finetuned at a later stage for some selctivity. if (!Controller.ControllerConfig.EnableATCommandSimulation) { SendMessage(CommunicationChannel.Command, commandBatch); } Controller.OnNotifiedTraceMessage(commandBatch.Remove(commandBatch.Length -1), NotificationSource.CommandCenter, TraceNotificationLevel.Information); stopWatch.Stop(); if (stopWatch.ElapsedMilliseconds < Constants.NavigationDataRefreshInterval) { Thread.Sleep((int)(Constants.NavigationDataRefreshInterval - stopWatch.ElapsedMilliseconds)); } if (!WorkerThreadATCommandsActive) { WorkerThreadATCommandsActive = true; } } catch (SocketException socketException) { switch (socketException.ErrorCode) { case 10060: //Socket timeout Controller.OnNotifiedTraceMessage(String.Format("AT :No activity on worker thread for {0} milliseconds.", Constants.SocketTimeoutNavigationData), NotificationSource.CommunicationCenter, TraceNotificationLevel.Error); WorkerThreadATCommandsActive = false; break; } } catch (Exception exception) { Controller.OnNotifiedTraceMessage("AT :" + exception.Message, NotificationSource.CommunicationCenter, TraceNotificationLevel.Error); } } while (Controller.ConnectionStatus != ConnectionStatus.Closed); }