// Event handler used to write the status of the stock to // the console. Additionally, if a the max number of stock thresholds // have been reached, the user is asked if they wish to continue. // If they do, the program continues, otherwise it exits. public void stockThresholdReached(object sender, StockNotificationEventArgs e) { // Using a lock ensures that no other thread tries to print to the // console at the same time. lock (thisLock) { Console.WriteLine(brokerName.PadRight(20) + e.Name.PadRight(20) + e.CurrentValue.ToString().PadRight(15) + e.NumberOfChanges.ToString().PadRight(15)); } }
// Method used to raise the event, called when the difference between // the stock's current value and its intial value is equal to the // threshold. protected void OnThresholdReached(StockNotificationEventArgs args1, StockToFileEventArgs args2) { // Using a lock ensures that no other thread tries to print to the // console at the same time. lock (thisLock) { // Calls the write to console event handler EventHandler<StockNotificationEventArgs> eventHandler = stockEvent; if (eventHandler != null) { eventHandler(this, args1); } // Calls the write to file event handler EventHandler<StockToFileEventArgs> fileHandler = stockToFileEvent; if (fileHandler != null) { fileHandler(this, args2); } } }