Example #1
0
        private async void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            await txt_Data.Dispatcher.InvokeAsync(() =>
            {
                if (dataQue.Count + txt_Data.LineCount >= app.AutoClearLines)
                {
                    txt_Data.Clear();
                }
                StringBuilder sbuf = new StringBuilder(dataQue.Count);
                while (dataQue.Count > 0)
                {
                    Core.DataReceivedEventArgs de = dataQue.Dequeue();
                    if (app.Timestamp && de.Time != null)
                    {
                        sbuf.AppendFormat("[{0}] ", ((DateTime)de.Time).ToString("MM/dd HH:mm:ss.ffff"));
                    }
                    sbuf.Append(de.Data);
                }
                txt_Data.AppendText(sbuf.ToString());
                if (app.AutoScroll)
                {
                    this.txt_Data.ScrollToEnd();
                }
            }, System.Windows.Threading.DispatcherPriority.Background);

            icc.DataReceived += dataReceived;
            icc.DataReceived -= unDataReceived;
            this.txt_Write.Focus();
            if (!isRun)
            {
                icc.Open();
                isRun = true;
            }
        }
Example #2
0
 public void StartLoad()
 {
     if (!isRun)
     {
         icc.DataReceived += (object sendor, Core.DataReceivedEventArgs ea) =>
         {
             try
             {
                 this.txt_Data.Dispatcher.Invoke(() =>
                 {
                     if (app.AutoClear)
                     {
                         if (this.txt_Data.LineCount >= app.AutoClearLines)
                         {
                             string s = this.txt_Data.Text.Substring(this.txt_Data.Text.Length / 2);
                             txt_Data.Clear();
                             txt_Data.Text = s;
                         }
                     }
                     if (!IsPause)
                     {
                         if (app.Timestamp && isNewLine)
                         {
                             this.txt_Data.AppendText(string.Format("[{0}] ", DateTime.Now.ToString("MM/dd HH:mm:ss.ffff")));
                         }
                         this.txt_Data.AppendText(ea.Data);
                         isNewLine = ea.isNewLine;
                         if (app.AutoScroll)
                         {
                             this.txt_Data.ScrollToEnd();
                         }
                     }
                 });
             }
             catch (Exception ex)
             {
                 Debug.WriteLine(ex.Message);
             }
         };
         icc.Open();
         isRun = true;
         this.txt_Write.DataContext = this.Icc;
     }
 }