Esempio n. 1
0
        private void OnTailButtonClick(object sender, RoutedEventArgs e)
        {
            if (btnTail.Content.ToString() == TailCommand)
            {
                if (string.IsNullOrEmpty(tbFileName.Text))
                {
                    MessageBox.Show(this, "Please specify a file for tailing.", this.Title,
                                    MessageBoxButton.OK, MessageBoxImage.Information, MessageBoxResult.OK);
                    return;
                }

                btnTail.Content       = CancelCommand;
                tbFileName.IsEnabled  = false;
                btnOpenFile.IsEnabled = false;
                tbFileData.Document.Blocks.Clear();

                try
                {
                    string[] args = new string[] {
                        @"-F",
                        tbFileName.Text
                    };

                    tail = new TailCommandLine(args);
                    tail.CommandLineException   += new EventHandler <CommandLineExceptionEventArgs>(OnCommandLineException);
                    tail.CommandLineDataChanged += new EventHandler <CommandLineDataChangedEventArgs>(OnCommandLineDataChanged);

                    ThreadPool.QueueUserWorkItem((WaitCallback)TailExecuter, tail);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(this, ex.Message, this.Title,
                                    MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK);
                }
            }
            else
            {
                btnTail.Content       = TailCommand;
                tbFileName.IsEnabled  = true;
                btnOpenFile.IsEnabled = true;

                try
                {
                    if (tail != null)
                    {
                        tail.CommandLineException   -= new EventHandler <CommandLineExceptionEventArgs>(OnCommandLineException);
                        tail.CommandLineDataChanged -= new EventHandler <CommandLineDataChangedEventArgs>(OnCommandLineDataChanged);
                        tail.Terminate();
                        tail.Dispose();
                        tail = null;
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(this, ex.Message, this.Title,
                                    MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK);
                }
            }
        }
Esempio n. 2
0
        private void TailExecuter(object state)
        {
            TailCommandLine tcl = (TailCommandLine)state;

            tcl.Execute();

            while (tail != null && tail.IsExecuting)
            {
                ;
            }
        }