}//close OnStockThresholdReached(...) protected virtual void OnWriteThresholdReached(StockThresholdReachedEventArgs e) { EventHandler <StockThresholdReachedEventArgs> handler = WriteThresholdReached; //make sure that the event is not null if (handler != null) { handler(this, e); // raise the event } }//close OnWriteThresholdReached(...)
}//close Activate() public void ChangeStockValue() { Random random = new Random(); //Declare random variable currentStockValue += random.Next(1, maxChange + 1); //update currentStockValue by random number //int randomNumber = random.Next(1, maxChange+1); //int sign = random.Next(0, 2); //randomNumber = (sign == 0) ? randomNumber : -randomNumber; //currentStockValue += randomNumber; numberOfChanges++; //increment the number of changes related to the designated stock. //if ((Math.Abs(currentStockValue - initialValue)) > notificationThreshold){ if ((currentStockValue - initialValue) > notificationThreshold) { lock (threadLock) { //lock - create critical section that can only be accessed by 1 thread at a time //Declare new StockThresholdReachedEventArgs StockThresholdReachedEventArgs args = new StockThresholdReachedEventArgs(); args.StockName = stockName; //set StockName data args.CurrentStockValue = currentStockValue; //set CurrentStockValue attribute args.StockChangeNum = numberOfChanges; //set StockChangeNum OnStockThresholdReached(args); //Raise Event - Display To Console OnWriteThresholdReached(args); //Raise Event - Write To Console }//close lock }//end if }//close ChangeStockValue()