예제 #1
0
        private void liquid_OverHeat(object sender, LiquidEventArgs e)
        {
            string message = e.Message;
            int    amount  = e.Amount;

            MessageBox.Show("Message: " + message + "\n" + "Over heat by: " + amount);
        }
예제 #2
0
 public void HeatLiquid(int amount)
 {
     cts2 = new CancellationTokenSource();
     CancellationToken token = cts2.Token;
     Task t1 = Task.Factory.StartNew(() =>
     {
         while (temperature <= highThreshold)
         {
             temperature += amount;
             if (temperature > highThreshold)
             {
                 if (OverHeat != null)
                 {
                     int tooHotBy       = highThreshold - temperature;
                     string message     = "Warning: Temperature Exceeded";
                     LiquidEventArgs le = new LiquidEventArgs(message, tooHotBy);
                     OverHeat(this, le);
                 }
             }
             if (token.IsCancellationRequested)
             {
                 token.ThrowIfCancellationRequested();
             }
             Thread.Sleep(1000);
         }
     }, token);
 }