private void btRead_Click(object sender, EventArgs e) { Queue myqueue = new Queue(); try { Inputfile inputfile = myqueue.ReadMessage(); if (myqueue.Count == 0) { btRead.Enabled = false; } logger.Info(String.Format("Read {0} from queue.", inputfile.File)); tbRead.AppendText(inputfile.File + Environment.NewLine); string fullPath = System.Reflection.Assembly.GetEntryAssembly().Location; string fileName = System.Reflection.Assembly.GetEntryAssembly().GetName().Name; string fileDir = Path.GetDirectoryName(fullPath); Thread thread = new Thread(() => RunBatch(Path.Combine(fileDir, "BatchScript", "run.bat"), inputfile.File)); thread.Start(); //Thread keepwindowup = new Thread(KeepWindowUp); //keepwindowup.Start(); //while (!thread.IsAlive) ; // Wait until the thread is in the background //Thread.Sleep(3000); //if (!this.Focused) // this.Focus(); } catch (Exception ex) { logger.Error(ex.Message); MessageBox.Show(ex.Message); } }
/// <summary> /// Event handler will add new files in watch folder to the queue /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OnChanged(object sender, FileSystemEventArgs e) { Inputfile inputfile = new Inputfile(); inputfile.File = e.FullPath; Queue myqueue = new Queue(); try { myqueue.WriteMessage(inputfile); logger.Info(String.Format("Added {0} to the queue.", inputfile.File)); // Need this to avoid cross-thread operation not valid error if (InvokeRequired) { BeginInvoke(new Action(() => { tbFilesFound.AppendText(e.FullPath.ToString() + Environment.NewLine); btRead.Enabled = true; })); } else { tbFilesFound.AppendText(e.FullPath.ToString() + Environment.NewLine); btRead.Enabled = true; } } catch (Exception ex) { logger.Error(ex.Message); MessageBox.Show(ex.Message); } }
private void btReadMessage_Click(object sender, EventArgs e) { Queue myqueue = new Queue(); try { Inputfile inputfile = myqueue.ReadMessage(); tbQueueStatus.AppendText(inputfile.File + Environment.NewLine); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void btWriteMessage_Click(object sender, EventArgs e) { Inputfile inputfile = new Inputfile(); inputfile.File = tbMessage.Text; Queue myqueue = new Queue(); try { myqueue.WriteMessage(inputfile); } catch (Exception ex) { MessageBox.Show(ex.Message); } MessageBox.Show("Message written successfully"); }