public void Stop() { lock ( LastTimers ) { PerfTiming Timing = LastTimers.Pop(); Timing.Stop(); } }
public void Start(string Name, bool Accum, Int64 Adder) { lock ( LastTimers ) { PerfTiming Timing = null; if (!Timings.TryGetValue(Name, out Timing)) { Timing = new PerfTiming(Name, Accum); Timings.Add(Name, Timing); } LastTimers.Push(Timing); Timing.IncrementCounter(Adder); Timing.Start(); } }
/// <summary> /// Execute a given command by sending it via the socket and wait for a reply. /// </summary> /// <param name="command">The command as an XML string</param> /// <param name="commandID">Id of command. Reply for this command must have same id</param> /// <param name="commandTimeout">Timeout in seconds. Max time waiting for a reply</param> /// <returns>The reply to the given command as an XML string</returns> public string execute(string command, string commandID, double commandTimeout) { string commandReply = ""; string reply = ""; bool timeout = false; Queue <string> debugData = new Queue <string>(); Queue <RfAlarm[]> alarmData = new Queue <RfAlarm[]>(); Queue <RfReport[]> reportData = new Queue <RfReport[]>(); try { if (RfReaderApi.showDebugInfo) { RfReaderApi.CurrentApi.ProvideInformation("CommandChannel", InformationType.Debug, "----msg----" + command); } // Make sure there is only one thread active if we send a command // and wait for an answer int bytesRead = 0; lock (this.communicationLock) { // first check for old data readAsyncData(ref debugData, ref alarmData, ref reportData); // Create the network stream NetworkStream stream = this.RfNetworkStream; // We have to encode the data for sending it over the network byte[] bytes = Encoding.ASCII.GetBytes(command); stream.Write(bytes, 0, bytes.Length); // setup timer PerfTiming perfTimer1 = new PerfTiming(); perfTimer1.Start(); // Wait for receiving a answer but only during a defined time period while (0 == commandReply.Length && (!timeout)) { try { System.Array.Clear(buffer, 0, buffer.Length); stream.ReadTimeout = 100; bytesRead = stream.Read(buffer, /*off*/ 0, CommandChannel.SendReceiveBufferSize); } catch (IOException /*ex */) { // No data available->empty message bytesRead = 0; } if (bytesRead > 0) { bytesRead = 0; // add read Data to reply message reply = reply + GetReply(buffer); if (RfReaderApi.showDebugInfo) { debugData.Enqueue("----reply----" + reply); } commandReply = FilterForCommmandReply(ref reply, commandID, stream, ref debugData, ref alarmData, ref reportData); } // check if we have time to try an other read if (commandTimeout < perfTimer1.End()) { timeout = true; } } } } catch (Exception ex) { if (RfReaderApi.showDebugInfo) { debugData.Enqueue(ex.ToString()); } throw new RfReaderApiException(RfReaderApiException.ResultCode_System, RfReaderApiException.Error_NoConnection); } finally { RfReaderApi.CurrentApi.deliverMessages(debugData, alarmData, reportData); } if (timeout) { throw new RfReaderApiException(RfReaderApiException.ResultCode_System, RfReaderApiException.Error_NoReply); } return(commandReply); }