MainWindow.xaml.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading;
  6. using System.Threading.Tasks;
  7. using System.Windows;
  8. using System.Windows.Controls;
  9. using System.Windows.Data;
  10. using System.Windows.Documents;
  11. using System.Windows.Input;
  12. using System.Windows.Media;
  13. using System.Windows.Media.Imaging;
  14. using System.Windows.Navigation;
  15. using System.Windows.Shapes;
  16. using Toolkit.Log4;
  17. namespace Toolkit
  18. {
  19. /// <summary>
  20. /// MainWindow.xaml 的交互逻辑
  21. /// </summary>
  22. public partial class MainWindow : Window
  23. {
  24. public MainWindow()
  25. {
  26. InitializeComponent();
  27. //ToolItems.Items.Add();
  28. this.Closing += MainWindow_Closing;
  29. Task.Run(() =>
  30. {
  31. string[] strs = new string[2];
  32. while (true)
  33. {
  34. if (LogHelper.logQueue.Count > 0)
  35. {
  36. if (LogHelper.logQueue.TryDequeue(out strs))
  37. {
  38. this.Dispatcher.Invoke( new Action(() => { LogShow.AppendText(strs[0] + " " + strs[1]+"\n"); }), null);
  39. this.Dispatcher.Invoke(new Action(() => { LogShow.ScrollToEnd(); }), null);
  40. }
  41. }
  42. if ( LogHelper.logQueue.Count > 100 )
  43. {
  44. LogHelper.logQueue = new System.Collections.Concurrent.ConcurrentQueue<string[]>();
  45. }
  46. Thread.Sleep(200);
  47. }
  48. });
  49. }
  50. private void MainWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
  51. {
  52. Environment.Exit(0);
  53. }
  54. }
  55. }