static LogStack compareWithFile(FileToMonitor fileToMonitor, LogStack logStack,LogStack historyStack) { if (!fileToMonitor.getPath().Equals(null)) { DateTime dateToCompare = File.GetLastWriteTime(fileToMonitor.getPath()); if (DateTime.Compare(dateToCompare, fileToMonitor.getTimeStamp()) > 0) { StreamReader sr = new StreamReader(fileToMonitor.getPath()); while (!sr.EndOfStream) { Node node = new Node(); string line = sr.ReadLine(); if(!line.Equals(historyStack.ViewHead())) { node.setText(line); logStack.Push(node); } } sr.Close(); } } return historyStack; }
private static void timer_Elapsed(FileToMonitor fileToMonitor,BackgroundWorker bgw1, LogStack logStack,LogStack historyStack) { object[] args = new object[3]; args[0] = fileToMonitor; args[1] = logStack; args[2] = historyStack; if (!bgw1.IsBusy) { bgw1.RunWorkerAsync(args); } }
private void WriteValuesToScreenFromThread(LogStack logStack, FileToMonitor fileToMonitor) { if (DateTime.Compare(File.GetLastWriteTime(fileToMonitor.getPath()), fileToMonitor.getTimeStamp()) > 0) { string text = String.Empty; while (!logStack.GetCount().Equals(0)) { Node node = logStack.Pop(); text = text + Environment.NewLine + node.getText(); historyStack.Push(node); } txtbxLogDisplay.Invoke((MethodInvoker)delegate { txtbxLogDisplay.Text = text; }); fileToMonitor.setDateTime(File.GetLastWriteTime(fileToMonitor.getPath())); } }