Esempio n. 1
0
        /// <summary>
        /// Changes the stock value and also raising the event of stock value changes
        /// </summary>
        public void ChangeStockValue()
        {
            var rand = new Random();

            CurrentValue += rand.Next(1, MaxChange + 1);

            NumChanges++;

            if ((CurrentValue - InitValue) > NotificationThreshold)
            {
                StockNotification args = new StockNotification();   //create event
                // Create event data
                args.StockName    = Name;
                args.CurrentValue = CurrentValue;
                args.NumChanges   = NumChanges;

                StockEvent?.Invoke(this, args); //raises event by invoking delegate
                StockChangeFile();
            }
        }
Esempio n. 2
0
        /// <summary>
        /// The eventhandler that raises the event of a change
        /// </summary>
        /// <param name="sender">The sender that indicated a change</param>
        /// <param name="e">Event arguments</param>
        public void StockEventHandler(Object sender, StockNotification e)
        {
            string statement = Name + " " + e.StockName + " " + e.CurrentValue + " " + e.NumChanges;

            Console.WriteLine(statement);
        }