示例#1
0
        /// <summary>
        /// An event to notify saving the following info to a text file when the threshold is reached:
        /// date & time, stock name, initial value, and current value
        /// </summary>
        public void StockChangeFile()
        {
            FileReachedEventArgs args = new FileReachedEventArgs(); //create event

            // Create event data
            args.DateAndTime  = DateAndTime;
            args.StockName    = Name;
            args.InitValue    = InitValue;
            args.CurrentValue = CurrentValue;

            FileReachedEvent?.Invoke(this, args);
        }
示例#2
0
        public void FileEventHandler(Object sender, FileReachedEventArgs e)
        {
            myLock.EnterWriteLock();

            string statement = e.DateAndTime + " " + e.StockName + " " + e.InitValue + " " + e.CurrentValue;

            try
            {
                using (StreamWriter outputFile = new StreamWriter(docPath, true))
                {
                    outputFile.WriteLine(statement);
                    outputFile.Close();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                myLock.ExitWriteLock();
            }
        }