private void Notify(object sender, ThresholdReachedEventArgs e)
 {
     lock (lockThis)
     {
         _stockInfo = _brokerName.PadRight(20)
                      + e.StockName.PadRight(20)
                      + e.CurrentValue.ToString().PadRight(20)
                      + e.Changes.ToString().PadRight(20);
         Console.WriteLine(_stockInfo);
         ReadWrite.SaveStockInfo(DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss tt").PadRight(30) + _stockInfo);
     }
 }
Example #2
0
 protected virtual void OnThresholdReached(ThresholdReachedEventArgs e)
 {
     /*
      * // C# 5.0
      * EventHandler<ThresholdReachedEventArgs> handler = ThresholdReached;
      * if (handler != null)
      * {
      *  handler(this, e);
      * }
      */
     // C# 6.0
     ThresholdReached?.Invoke(this, e);
 }
Example #3
0
        // Raise the event
        private void ChangeStockValue()
        {
            Random rnd = new Random();

            _stockCurrentValue += rnd.Next(1, _maxChange);

            if (_stockCurrentValue - _stockInitialValue > _threshold)
            {
                _numberChanges++;
                ThresholdReachedEventArgs args = new ThresholdReachedEventArgs();
                args.StockName    = _stockName;
                args.CurrentValue = _stockCurrentValue;
                args.Changes      = _numberChanges;
                OnThresholdReached(args);
            }
        }