领胜LDS 键盘AOI检测项目
xcd
2020-07-01 9d05b4e5a7b667afb6d13cbcb460e377c175c170
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
using Bro.Common.Helper;
using Bro.UI.Model.Winform;
using System;
using System.Collections.Concurrent;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
 
namespace Bro.UI.Config.MenuForms
{
    [DockOption(WeifenLuo.WinFormsUI.Docking.DockState.DockBottom, 0, 200)]
    [MenuNode("Log", "日志", 3, "View1", true)]
    public partial class FrmLog : MenuFrmBase
    {
        public FrmLog()
        {
            InitializeComponent();
        }
 
        readonly ConcurrentQueue<LogMsg> _logQueue = new ConcurrentQueue<LogMsg>();
        Task _logTask = null;
        static readonly object _logLock = new object();
 
        public override void LogDisplay(LogMsg msg)
        {
            _logQueue.Enqueue(msg);
 
            lock (_logLock)
            {
                if (_logTask == null)
                {
                    _logTask = Task.Run(() =>
                    {
                        while (true)
                        {
                            StringBuilder txt = new StringBuilder();
                            while (_logQueue.Count > 0)
                            {
                                if (_logQueue.TryDequeue(out LogMsg log))
                                {
                                    txt.AppendLine($"{log.LogTime.ToString("yyyy-MM-dd HH:mm:ss.fff")}\t{log.Prefix}\t{log.Msg}");
                                }
                            }
 
                            Invoke(new Action(() =>
                            {
                                //if (txtLog.IsHandleCreated)
                                {
                                    txtLog.AppendText(txt.ToString());
                                }
                            }));
                            Thread.Sleep(1000);
                        }
                    });
                }
            }
        }
 
        private void tsmiClearLog_Click(object sender, EventArgs e)
        {
            txtLog.Clear();
        }
    }
}