Exemplo n.º 1
0
 static async Task SendMonitoringMessages(IDuplexBroker broker, CancellationToken cancellationToken)
 {
     var cpuCounter = new PerformanceCounter("Processor", "% Processor Time", "_Total");
     ISerializer aSerializer = new DataContractJsonStringSerializer();
     while (!cancellationToken.IsCancellationRequested)
     {
         CpuUpdateMessage aMessage = new CpuUpdateMessage();
         aMessage.Usage = cpuCounter.NextValue();
         object aSerializedMessage = aSerializer.Serialize<CpuUpdateMessage>(aMessage);
         broker.SendMessage("MyCpuUpdate", aSerializedMessage);
         try
         {
             await Task.Delay(500, cancellationToken);
         }
         catch (TaskCanceledException)
         {
         }
     }
 }