{"id":107014,"date":"2026-09-18T18:56:38","date_gmt":"2026-09-18T10:56:38","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/107014.html"},"modified":"2026-09-18T18:56:38","modified_gmt":"2026-09-18T10:56:38","slug":"c-%e7%95%8c%e9%9d%a2%e5%8d%a1%e9%a1%bf%ef%bc%9a%e4%bb%8e%e5%ae%9a%e4%bd%8d%e5%88%b0%e6%a0%b9%e6%b2%bb","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/107014.html","title":{"rendered":"C# \u754c\u9762\u5361\u987f\uff1a\u4ece\u5b9a\u4f4d\u5230\u6839\u6cbb"},"content":{"rendered":"<h3>\u4e00\u3001\u5148\u7edf\u4e00\u8ba4\u77e5&#xff1a;\u5361\u987f\u5230\u5e95\u662f\u4ec0\u4e48<\/h3>\n<p>Windows \u684c\u9762\u7a0b\u5e8f\u7684 UI \u6709\u4e00\u4e2a\u94c1\u5f8b&#xff1a;\u53ea\u6709\u4e00\u4e2a UI \u7ebf\u7a0b&#xff0c;\u5b83\u9760\u4e00\u4e2a\u6d88\u606f\u6cf5&#xff08;Message Loop&#xff09;\u6d3b\u7740\u3002\u9f20\u6807\u70b9\u51fb\u3001\u952e\u76d8\u8f93\u5165\u3001\u91cd\u7ed8\u8bf7\u6c42\u3001\u5b9a\u65f6\u5668\u3001Invoke \u56de\u8c03&#xff0c;\u5168\u90fd\u662f\u6392\u8fdb\u8fd9\u4e2a\u961f\u5217\u7684\u4e00\u6761\u6761\u6d88\u606f&#xff0c;UI \u7ebf\u7a0b\u4e00\u6761\u6761\u5904\u7406\u3002<\/p>\n<p>\u4e8e\u662f\u7ed3\u8bba\u975e\u5e38\u76f4\u63a5&#xff1a;<\/p>\n<p>UI \u7ebf\u7a0b\u4e0a\u4efb\u4f55\u4e00\u6b21\u6267\u884c\u8d85\u8fc7 ~100ms&#xff0c;\u7528\u6237\u5c31\u80fd\u660e\u786e\u611f\u89c9\u5230&#034;\u5361&#034;&#xff1b;\u8d85\u8fc7 50ms \u5c31\u5df2\u7ecf\u4e0d\u8ddf\u624b\u4e86\u3002<\/p>\n<p>\u6309 60fps \u7b97&#xff0c;\u4e00\u5e27\u53ea\u6709 16.7ms\u3002\u5982\u679c\u4f60\u8981\u7684\u662f&#034;\u6d41\u7545\u52a8\u753b&#034;&#xff0c;\u9884\u7b97\u5c31\u53ea\u6709 16ms\u3002<\/p>\n<h4>\u5173\u952e\u533a\u5206&#xff1a;\u7a0b\u5e8f\u6162 \u2260 \u754c\u9762\u5361<\/h4>\n<table>\n<tr>\n<p>\u73b0\u8c61<\/p>\n<p>\u672c\u8d28<\/p>\n<\/tr>\n<tbody>\n<tr>\n<td>\n<p>\u540e\u53f0\u8ba1\u7b97\u8dd1\u4e86 10 \u79d2&#xff0c;\u4f46\u754c\u9762\u80fd\u70b9\u80fd\u62d6<\/p>\n<\/td>\n<td>\n<p>\u7a0b\u5e8f\u6162&#xff0c;\u4e0d\u662f\u5361\u987f\u95ee\u9898\u200b<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>\u540e\u53f0\u5f88\u5feb&#xff0c;\u4f46\u70b9\u4e00\u4e0b\u6309\u94ae\u754c\u9762\u5c31\u50f5\u4f4f<\/p>\n<\/td>\n<td>\n<p>UI \u7ebf\u7a0b\u88ab\u5360&#xff0c;\u8fd9\u662f\u5361\u987f\u200b<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u5f88\u591a\u4eba\u82b1\u5927\u529b\u6c14\u4f18\u5316\u7b97\u6cd5&#xff0c;\u754c\u9762\u7167\u6837\u5361\u2014\u2014\u56e0\u4e3a\u74f6\u9888\u6839\u672c\u4e0d\u5728\u7b97\u6cd5&#xff0c;\u800c\u5728&#034;\u8fd9\u6bb5\u6d3b\u5e72\u5728\u4e86 UI \u7ebf\u7a0b\u4e0a&#034;\u3002\u5148\u5206\u6e05\u8fd9\u4e2a&#xff0c;\u80fd\u7701\u6389\u4e00\u534a\u65e0\u7528\u529f\u3002<\/p>\n<hr \/>\n<h3>\u4e8c\u3001\u5361\u987f\u7684\u56db\u79cd\u5178\u578b\u6210\u56e0<\/h3>\n<h4>1. \u771f\u00b7\u963b\u585e \u2014\u2014 \u91cd\u6d3b\u5e72\u5728\u4e86 UI \u7ebf\u7a0b\u4e0a<\/h4>\n<p>\/\/ \u274c \u5178\u578b&#xff1a;\u6309\u94ae\u4e8b\u4ef6\u91cc\u540c\u6b65\u5e72\u91cd\u6d3b<br \/>\nprivate void btnQuery_Click(object sender, EventArgs e)<br \/>\n{<br \/>\n    var dt &#061; dbHelper.Query(&#034;SELECT * FROM History WHERE &#8230;&#034;); \/\/ \u540c\u6b65\u6570\u636e\u5e93\u67e5\u8be2&#xff0c;3\u79d2<br \/>\n    dataGridView1.DataSource &#061; dt;<br \/>\n    File.WriteAllText(logPath, BuildBigReport());               \/\/ \u540c\u6b65\u5199\u5927\u6587\u4ef6<br \/>\n}<\/p>\n<p>\u5e38\u89c1\u5143\u51f6&#xff1a;\u6570\u636e\u5e93\u67e5\u8be2\u3001\u6587\u4ef6\u8bfb\u5199\u3001HTTP\/\u4e32\u53e3\/PLC \u901a\u8baf\u3001\u5927\u91cf\u5e8f\u5217\u5316\u53cd\u5e8f\u5217\u5316\u3001\u52a0\u5bc6\u89e3\u5bc6\u3001\u56fe\u50cf\u5904\u7406\u3001Excel \u5bfc\u51fa\u3001\u590d\u6742 LINQ to Objects \u904d\u5386\u3001\u5b57\u7b26\u4e32\u5927\u91cf\u62fc\u63a5\u3002<\/p>\n<h4>2. \u4f2a\u00b7\u963b\u585e \u2014\u2014 \u6b7b\u9501&#xff08;\u6700\u5bb9\u6613\u8e29&#xff0c;\u4e14\u6700\u9690\u853d&#xff09;<\/h4>\n<p>\/\/ \u274c \u7528\u4e86 async&#xff0c;\u5374\u5728 UI \u7ebf\u7a0b\u540c\u6b65\u7b49\u5f85 \u2192 \u76f4\u63a5\u6b7b\u9501<br \/>\nprivate void btnLoad_Click(object sender, EventArgs e)<br \/>\n{<br \/>\n    var data &#061; LoadAsync().Result;              \/\/ \u6b7b\u7b49<br \/>\n    \/\/ \u6216 LoadAsync().Wait();<br \/>\n    \/\/ \u6216 LoadAsync().GetAwaiter().GetResult();<br \/>\n}<\/p>\n<p>\u539f\u7406&#xff1a;LoadAsync() \u5185\u90e8\u7684 await \u5b8c\u6210\u540e&#xff0c;\u9700\u8981\u5207\u56de UI \u7ebf\u7a0b\u7684 SynchronizationContext \u624d\u80fd\u7ee7\u7eed\u6267\u884c&#xff1b;\u4f46 UI \u7ebf\u7a0b\u6b63\u5361\u5728 .Result \u4e0a\u7b49\u5b83 \u2014\u2014 \u4e92\u76f8\u7b49\u5f85&#xff0c;\u6c38\u4e45\u6b7b\u9501\u3002\u754c\u9762\u8868\u73b0\u4e3a\u5f7b\u5e95\u5047\u6b7b&#xff0c;\u65e0\u4efb\u4f55\u5f02\u5e38\u629b\u51fa&#xff0c;\u6781\u96be\u5bdf\u89c9\u3002<\/p>\n<h4>3. \u6d2a\u6c34 \u2014\u2014 \u9ad8\u9891\u5237\u65b0 \/ \u4e8b\u4ef6\u98ce\u66b4<\/h4>\n<p>\u5de5\u63a7\u573a\u666f\u7684\u5934\u53f7\u6740\u624b\u3002PLC \u6bcf\u79d2\u63a8\u6765\u51e0\u5343\u4e2a\u6570\u636e\u70b9&#xff0c;\u4f60\u5728\u56de\u8c03\u91cc\u4e00\u4e2a\u70b9\u4e00\u6b21 Invoke \u66f4\u65b0\u63a7\u4ef6&#xff1a;<\/p>\n<p>\/\/ \u274c \u6bcf\u4e2a\u6570\u636e\u70b9\u90fd\u8de8\u7ebf\u7a0b\u5237\u65b0\u4e00\u6b21 UI<br \/>\nvoid OnPlcData(Sample s)<br \/>\n{<br \/>\n    this.Invoke(() &#061;&gt; label1.Text &#061; s.Value.ToString());<br \/>\n}<\/p>\n<p>\u6bcf\u79d2\u51e0\u5343\u6b21 Invoke &#061; \u51e0\u5343\u6761\u6d88\u606f\u6392\u8fdb UI \u961f\u5217&#xff0c;UI \u7ebf\u7a0b\u5149\u5904\u7406\u66f4\u65b0\u5c31\u7d2f\u6b7b&#xff0c;\u70b9\u51fb\u548c\u91cd\u7ed8\u5168\u88ab\u6324\u5230\u540e\u9762\u3002<\/p>\n<p>\u540c\u7c7b\u95ee\u9898&#xff1a;TextChanged\u3001MouseMove\u3001Scroll\u3001SelectionChanged\u3001Paint \u91cc\u505a\u91cd\u6d3b&#xff1b;ObservableCollection \u9010\u6761 Add \u89e6\u53d1\u9010\u6761\u901a\u77e5\u3002<\/p>\n<h4>4. \u6e32\u67d3\u8d1f\u62c5 \u2014\u2014 \u5e03\u5c40\u3001\u7ed8\u5236\u3001GC<\/h4>\n<ul>\n<li>\u51e0\u767e\u4e2a\u63a7\u4ef6\u540c\u65f6 SuspendLayout \u7f3a\u5931\u5bfc\u81f4\u53cd\u590d\u5e03\u5c40<\/li>\n<li>OnPaint \u91cc\u505a\u4f4d\u56fe\u7f29\u653e\u3001\u6297\u952f\u9f7f\u91cd\u7ed8\u3001\u8bfb\u6587\u4ef6<\/li>\n<li>WPF \u5e03\u5c40\u6296\u52a8&#xff08;Layout Thrashing&#xff09;\u3001\u672a\u542f\u7528 UI \u865a\u62df\u5316<\/li>\n<li>\u5927\u5bf9\u8c61\u9891\u7e41\u5206\u914d\u5f15\u53d1 Gen2 GC&#xff0c;STW \u6682\u505c\u8868\u73b0\u4e3a&#034;\u5468\u671f\u6027\u987f\u4e00\u4e0b&#034;<\/li>\n<\/ul>\n<hr \/>\n<h3>\u4e09\u3001\u5148\u628a\u5361\u987f&#034;\u6293\u73b0\u884c&#034;&#xff08;\u522b\u9760\u731c&#xff09;<\/h3>\n<h4>3.1 UI \u5fc3\u8df3\u770b\u95e8\u72d7&#xff08;\u6700\u5b9e\u7528&#xff0c;10 \u5206\u949f\u5c31\u80fd\u52a0\u4e0a&#xff09;<\/h4>\n<p>\u539f\u7406&#xff1a;UI \u7ebf\u7a0b\u653e\u4e00\u4e2a 50ms \u7684\u5b9a\u65f6\u5668&#xff0c;\u5982\u679c\u67d0\u6b21 Tick \u59d7\u59d7\u6765\u8fdf&#xff0c;\u8fdf\u5230\u591a\u4e45 &#061; UI \u7ebf\u7a0b\u88ab\u963b\u585e\u4e86\u591a\u4e45\u3002\u8fd9\u662f\u552f\u4e00\u80fd\u76f4\u63a5\u91cf\u5316&#034;\u5361\u4e86\u591a\u4e45&#034;\u7684\u4f4e\u6210\u672c\u624b\u6bb5\u3002<\/p>\n<p>WPF \u7248&#xff1a;<\/p>\n<p>public static class UiWatchdog<br \/>\n{<br \/>\n    public static void Start(int toleranceMs &#061; 100, Action&lt;long&gt;? onStall &#061; null)<br \/>\n    {<br \/>\n        var sw &#061; Stopwatch.StartNew();<br \/>\n        long last &#061; sw.ElapsedMilliseconds;<br \/>\n        var timer &#061; new DispatcherTimer(DispatcherPriority.Normal)<br \/>\n        {<br \/>\n            Interval &#061; TimeSpan.FromMilliseconds(50)<br \/>\n        };<br \/>\n        timer.Tick &#043;&#061; (_, _) &#061;&gt;<br \/>\n        {<br \/>\n            long now &#061; sw.ElapsedMilliseconds;<br \/>\n            long gap &#061; now &#8211; last;<br \/>\n            last &#061; now;<br \/>\n            if (gap &gt; toleranceMs)<br \/>\n            {<br \/>\n                \/\/ gap \u5c31\u662f\u5b9e\u6d4b\u963b\u585e\u65f6\u957f<br \/>\n                Debug.WriteLine($&#034;[UI STALL] {gap}ms &#064; {DateTime.Now:HH:mm:ss.fff}&#034;);<br \/>\n                onStall?.Invoke(gap);<br \/>\n            }<br \/>\n        };<br \/>\n        timer.Start();<br \/>\n    }<br \/>\n}<\/p>\n<p>WinForms \u7248&#xff08;System.Windows.Forms.Timer \u540c\u6837\u662f\u6d88\u606f\u9a71\u52a8&#xff0c;\u6548\u679c\u4e00\u81f4&#xff09;&#xff1a;<\/p>\n<p>var sw &#061; Stopwatch.StartNew();<br \/>\nlong last &#061; 0;<br \/>\nvar t &#061; new System.Windows.Forms.Timer { Interval &#061; 50 };<br \/>\nt.Tick &#043;&#061; (_, _) &#061;&gt;<br \/>\n{<br \/>\n    long now &#061; sw.ElapsedMilliseconds;<br \/>\n    long gap &#061; now &#8211; last;<br \/>\n    last &#061; now;<br \/>\n    if (gap &gt; 100) Debug.WriteLine($&#034;[UI STALL] {gap}ms&#034;);<br \/>\n};<br \/>\nt.Start();<\/p>\n<p>\u4e0a\u7ebf\u524d\u5173\u6389\u6216\u964d\u9891\u5373\u53ef\u3002\u6709\u4e86\u5b83&#xff0c;\u4f60\u5c31\u4ece&#034;\u7528\u6237\u8bf4\u5361&#034;\u53d8\u6210\u4e86&#034;\u65e5\u5fd7\u663e\u793a 14:23:07 \u5361\u4e86 840ms&#034;\u3002<\/p>\n<h4>3.2 \u4e13\u4e1a\u5de5\u5177&#xff08;\u5b9a\u4f4d\u5230\u5177\u4f53\u65b9\u6cd5&#xff09;<\/h4>\n<table>\n<tr>\n<p>\u5de5\u5177<\/p>\n<p>\u7528\u9014<\/p>\n<\/tr>\n<tbody>\n<tr>\n<td>\n<p>Visual Studio \u6027\u80fd\u63a2\u67e5\u5668&#xff08;Alt&#043;F2&#xff09;<\/p>\n<\/td>\n<td>\n<p>\u5185\u7f6e&#xff0c;\u770b CPU \u91c7\u6837\u3001\u70ed\u70b9\u65b9\u6cd5\u8c03\u7528\u6811<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>dotTrace \/ ANTS Performance Profiler\u200b<\/p>\n<\/td>\n<td>\n<p>\u5546\u4e1a&#xff0c;Timeline \u6a21\u5f0f\u80fd\u76f4\u63a5\u770b\u5230 UI \u7ebf\u7a0b\u54ea\u4e00\u6bb5\u88ab\u963b\u585e<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>PerfView \/ ETW\u200b<\/p>\n<\/td>\n<td>\n<p>\u514d\u8d39\u4e14\u6700\u5f3a&#xff0c;\u80fd\u770b GC \u6682\u505c\u3001\u7ebf\u7a0b\u7b49\u5f85\u3001\u78c1\u76d8 IO<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>Windows \u6027\u80fd\u5206\u6790\u5668&#xff08;WPA&#xff09;\u200b<\/p>\n<\/td>\n<td>\n<p>\u914d\u5408 ETW \u5206\u6790 UI \u5ef6\u8fdf&#xff08;UI Delay \u5206\u6790&#xff09;<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u5b9e\u64cd\u5efa\u8bae&#xff1a;\u5148\u7528\u770b\u95e8\u72d7\u786e\u8ba4&#034;\u786e\u5b9e\u5361 &#043; \u5361\u591a\u4e45&#034;&#xff0c;\u518d\u7528 dotTrace Timeline \u6293\u4e00\u6bb5&#xff0c;\u76f4\u63a5\u770b UI \u7ebf\u7a0b\u4e0a\u90a3\u4e00\u5927\u6761\u5b9e\u5fc3\u5757\u662f\u4ec0\u4e48\u65b9\u6cd5\u2014\u201490% \u7684\u60c5\u51b5\u4e00\u773c\u5c31\u7834\u6848\u3002<\/p>\n<h4>3.3 \u571f\u529e\u6cd5\u4e5f\u6709\u6548<\/h4>\n<p>\u5728\u53ef\u7591\u65b9\u6cd5\u524d\u540e\u6253 Stopwatch&#xff0c;\u6216\u57cb\u4e00\u4e2a\u5168\u5c40\u7684\u8017\u65f6\u65e5\u5fd7&#xff1a;<\/p>\n<p>public static IDisposable Measure(string name)<br \/>\n{<br \/>\n    var sw &#061; Stopwatch.StartNew();<br \/>\n    return new Disposer(() &#061;&gt; Debug.WriteLine($&#034;{name}: {sw.ElapsedMilliseconds}ms&#034;));<br \/>\n}<\/p>\n<hr \/>\n<h3>\u56db\u3001\u9010\u4e2a\u51fb\u7834&#xff1a;\u4ece&#034;\u80fd\u8dd1&#034;\u5230&#034;\u4e0d\u5361&#034;<\/h3>\n<h4>4.1 \u628a\u91cd\u6d3b\u642c\u79bb UI \u7ebf\u7a0b&#xff08;\u6b63\u786e\u59ff\u52bf&#xff09;<\/h4>\n<p>\/\/ \u2705 \u4e8b\u4ef6\u5904\u7406\u5668\u53ef\u4ee5 async void&#xff08;\u8fd9\u662f\u552f\u4e00\u63a8\u8350\u7684 async void \u573a\u666f&#xff09;<br \/>\nprivate async void btnQuery_Click(object sender, EventArgs e)<br \/>\n{<br \/>\n    btnQuery.Enabled &#061; false;<br \/>\n    try<br \/>\n    {<br \/>\n        \/\/ Task.Run \u628a CPU \u5bc6\u96c6\u6d3b\u4e22\u7ebf\u7a0b\u6c60&#xff1b;IO \u5bc6\u96c6\u6d3b\u76f4\u63a5 await \u539f\u751f\u5f02\u6b65 API<br \/>\n        var dt &#061; await Task.Run(() &#061;&gt; dbHelper.Query(sql));<br \/>\n        dataGridView1.DataSource &#061; dt;      \/\/ await \u4e4b\u540e\u81ea\u52a8\u56de\u5230 UI \u7ebf\u7a0b<br \/>\n    }<br \/>\n    catch (Exception ex)<br \/>\n    {<br \/>\n        MessageBox.Show(ex.Message);<br \/>\n    }<br \/>\n    finally<br \/>\n    {<br \/>\n        btnQuery.Enabled &#061; true;<br \/>\n    }<br \/>\n}<\/p>\n<p>\u8981\u70b9&#xff1a;<\/p>\n<ul>\n<li>IO \u5bc6\u96c6\u578b&#xff08;\u6570\u636e\u5e93\u3001\u6587\u4ef6\u3001\u7f51\u7edc\u3001\u4e32\u53e3&#xff09;\u4f18\u5148\u7528\u539f\u751f\u5f02\u6b65 API&#xff08;ExecuteReaderAsync\u3001ReadAsync\u3001HttpClient \u7b49&#xff09;&#xff0c;\u4e0d\u8981\u50bb\u4e4e\u4e4e\u5168\u585e Task.Run\u2014\u2014\u90a3\u53ea\u662f\u6362\u4e2a\u7ebf\u7a0b\u963b\u585e&#xff0c;\u767d\u767d\u5360\u7ebf\u7a0b\u6c60\u3002<\/li>\n<li>CPU \u5bc6\u96c6\u578b&#xff08;\u56fe\u50cf\u5904\u7406\u3001\u590d\u6742\u8ba1\u7b97\u3001\u5927\u62a5\u8868\u751f\u6210&#xff09;\u624d\u7528 Task.Run\u3002<\/li>\n<li>async void \u53ea\u7528\u4e8e\u4e8b\u4ef6\u5904\u7406\u5668&#xff0c;\u5176\u4ed6\u4e00\u5f8b async Task\u3002<\/li>\n<li>\u4e00\u5b9a\u8981 try\/catch&#xff0c;\u5426\u5219\u5f02\u5e38\u4f1a\u88ab\u541e\u8fdb SynchronizationContext&#xff0c;\u8868\u73b0\u4e3a&#034;\u7a0b\u5e8f\u83ab\u540d\u5176\u5999\u6ca1\u53cd\u5e94&#034;\u3002<\/li>\n<\/ul>\n<h4>4.2 \u6d88\u706d\u6b7b\u9501&#xff1a;\u4e00\u8def async &#043; ConfigureAwait(false)<\/h4>\n<p>\/\/ \u2705 \u5e93\u4ee3\u7801\u4e00\u5f8b ConfigureAwait(false)&#xff0c;\u4e0d\u6355\u83b7 UI \u4e0a\u4e0b\u6587<br \/>\npublic async Task&lt;DataTable&gt; LoadAsync()<br \/>\n{<br \/>\n    using var conn &#061; new SqlConnection(cs);<br \/>\n    await conn.OpenAsync().ConfigureAwait(false);<br \/>\n    \/\/ &#8230;<br \/>\n}<\/p>\n<p>\u89c4\u5219&#xff1a;<\/p>\n<ul>\n<li>\u5e95\u5c42\u5e93\/\u670d\u52a1\u5c42&#xff1a;\u6240\u6709 await \u52a0 .ConfigureAwait(false)&#xff0c;\u5f7b\u5e95\u65ad\u5f00\u4e0e UI \u4e0a\u4e0b\u6587\u7684\u8026\u5408\u3002<\/li>\n<li>UI \u5c42&#xff1a;\u9700\u8981\u66f4\u65b0\u63a7\u4ef6\u7684\u5730\u65b9\u5c31\u6b63\u5e38 await&#xff08;\u56de\u5230 UI \u7ebf\u7a0b&#xff09;\u3002<\/li>\n<li>\u7edd\u4e0d\u5728 UI \u7ebf\u7a0b\u5199 .Result \/ .Wait() \/ .GetAwaiter().GetResult()\u3002\u7528 IDE \u89c4\u5219\u6216 ConfigureAwait \u5206\u6790\u5668&#xff08;\u5982 Meziantou.Analyzer&#xff09;\u5361\u4f4f\u8fd9\u4e00\u70b9\u3002<\/li>\n<\/ul>\n<h4>4.3 \u9ad8\u9891\u4e8b\u4ef6&#xff1a;\u8282\u6d41&#xff08;Throttle&#xff09;\u4e0e\u9632\u6296&#xff08;Debounce&#xff09;<\/h4>\n<p>\/\/ \u9632\u6296&#xff1a;\u505c\u6b62\u89e6\u53d1 N \u6beb\u79d2\u540e\u624d\u6267\u884c\u4e00\u6b21&#xff08;\u9002\u5408 TextChanged \u641c\u7d22&#xff09;<br \/>\npublic static Action Debounce(Action action, int delayMs)<br \/>\n{<br \/>\n    System.Timers.Timer? timer &#061; null;<br \/>\n    return () &#061;&gt;<br \/>\n    {<br \/>\n        timer?.Stop();<br \/>\n        timer?.Dispose();<br \/>\n        timer &#061; new System.Timers.Timer(delayMs) { AutoReset &#061; false };<br \/>\n        timer.Elapsed &#043;&#061; (_, _) &#061;&gt; action();<br \/>\n        timer.Start();<br \/>\n    };<br \/>\n}<\/p>\n<p>\/\/ \u7528\u6cd5&#xff1a;textBox.TextChanged &#043;&#061; (_, _) &#061;&gt; debouncedSearch();<\/p>\n<p>\/\/ \u8282\u6d41&#xff1a;\u56fa\u5b9a\u9891\u7387\u6700\u591a\u6267\u884c\u4e00\u6b21&#xff08;\u9002\u5408 MouseMove\u3001Scroll&#xff09;<br \/>\nprivate DateTime _lastThrottled &#061; DateTime.MinValue;<br \/>\nvoid OnMouseMove(object sender, MouseEventArgs e)<br \/>\n{<br \/>\n    var now &#061; DateTime.Now;<br \/>\n    if ((now &#8211; _lastThrottled).TotalMilliseconds &lt; 50) return;<br \/>\n    _lastThrottled &#061; now;<br \/>\n    DoWork(e);<br \/>\n}<\/p>\n<h4>4.4 \u6279\u91cf\u5237\u65b0&#xff1a;\u522b\u4e00\u6761\u6570\u636e\u5237\u4e00\u6b21&#xff08;\u5de5\u63a7\u573a\u666f\u5fc5\u505a&#xff09;<\/h4>\n<p>\u6838\u5fc3\u601d\u60f3&#xff1a;\u540e\u53f0\u9ad8\u901f\u6536&#xff0c;UI \u5b9a\u9891\u753b\u3002\u7528 Channel \u505a\u7f13\u51b2&#xff0c;UI \u4fa7\u56fa\u5b9a 10~20fps \u6210\u6279\u6e32\u67d3\u3002<\/p>\n<p>private readonly Channel&lt;Sample&gt; _queue &#061; Channel.CreateUnbounded&lt;Sample&gt;();<br \/>\nprivate readonly CancellationTokenSource _cts &#061; new();<\/p>\n<p>\/\/ \u540e\u53f0\u91c7\u96c6&#xff1a;\u591a\u5feb\u90fd\u884c&#xff0c;\u53ea\u7ba1\u5f80\u961f\u5217\u91cc\u6254<br \/>\nprivate async Task CollectLoopAsync(CancellationToken ct)<br \/>\n{<br \/>\n    while (!ct.IsCancellationRequested)<br \/>\n    {<br \/>\n        var s &#061; await ReadFromPlcAsync(ct);<br \/>\n        _queue.Writer.TryWrite(s);            \/\/ \u65e0\u9501\u3001\u65e0\u963b\u585e<br \/>\n        await Task.Delay(10, ct);<br \/>\n    }<br \/>\n}<\/p>\n<p>\/\/ UI \u4fa7&#xff1a;\u56fa\u5b9a 100ms&#xff08;10fps&#xff09;\u6279\u91cf\u51fa\u5e27&#xff0c;\u4eba\u773c\u5b8c\u5168\u591f\u7528<br \/>\nprivate async Task UiPumpAsync(CancellationToken ct)<br \/>\n{<br \/>\n    var buffer &#061; new List&lt;Sample&gt;(4096);<br \/>\n    using var timer &#061; new PeriodicTimer(TimeSpan.FromMilliseconds(100)); \/\/ .NET 6&#043;<br \/>\n    while (await timer.WaitForNextTickAsync(ct))<br \/>\n    {<br \/>\n        while (_queue.Reader.TryRead(out var s)) buffer.Add(s);<br \/>\n        if (buffer.Count &#061;&#061; 0) continue;<\/p>\n<p>        RenderBatch(buffer);    \/\/ \u4e00\u6b21\u7ed8\u5236\u4e00\u6279&#xff0c;\u800c\u4e0d\u662f\u51e0\u5343\u6b21<br \/>\n        buffer.Clear();<br \/>\n    }<br \/>\n}<\/p>\n<p>\u6548\u679c&#xff1a;\u6bcf\u79d2 5000 \u4e2a\u6570\u636e\u70b9 \u2192 UI \u6bcf\u79d2\u53ea\u5237\u65b0 10 \u6b21&#xff0c;CPU \u4ece 90% \u964d\u5230\u4e2a\u4f4d\u6570\u3002\u4eba\u773c 10fps \u770b\u6570\u503c\u548c\u66f2\u7ebf\u5b8c\u5168\u8db3\u591f&#xff0c;\u786c\u8981 60fps \u662f\u81ea\u627e\u9ebb\u70e6\u3002<\/p>\n<p>Channel \u9700\u8981 System.Threading.Channels&#xff1b;.NET Framework \u7528\u6237\u53ef\u7528 BlockingCollection&lt;T&gt; \u6216 ConcurrentQueue&lt;T&gt; \u66ff\u4ee3&#xff08;\u6ce8\u610f\u522b\u5728 UI \u7ebf\u7a0b Take&#xff09;\u3002<\/p>\n<h4>4.5 \u63a7\u4ef6\u7684\u6b63\u786e\u7528\u6cd5<\/h4>\n<p>WinForms&#xff1a;<\/p>\n<p>\/\/ \u6279\u91cf\u7ed3\u6784\u53d8\u66f4&#xff1a;\u6302\u8d77\u5e03\u5c40&#xff0c;\u6700\u540e\u4e00\u6b21\u6027\u6062\u590d<br \/>\ndataGridView1.SuspendLayout();<br \/>\ntry<br \/>\n{<br \/>\n    dataGridView1.Rows.Add(&#8230;);   \/\/ \u52a0 1000 \u884c<br \/>\n}<br \/>\nfinally { dataGridView1.ResumeLayout(); }<\/p>\n<p>\/\/ TreeView \/ ListView \u540c\u7406<br \/>\ntreeView1.BeginUpdate();<br \/>\ntry { \/* \u6279\u91cf\u589e\u5220\u6539 *\/ } finally { treeView1.EndUpdate(); }<\/p>\n<ul>\n<li>\u5927\u6570\u636e\u91cf\u5217\u8868\u52a1\u5fc5\u7528\u865a\u62df\u6a21\u5f0f&#xff1a;DataGridView.VirtualMode &#061; true &#043; CellValueNeeded \u4e8b\u4ef6&#xff0c;\u6216 ListView.VirtualMode\u300210 \u4e07\u884c\u6570\u636e\u53ea\u6e32\u67d3\u5c4f\u5e55\u4e0a\u53ef\u89c1\u7684\u51e0\u5341\u884c&#xff0c;\u6027\u80fd\u5929\u58e4\u4e4b\u522b\u3002<\/li>\n<li>\u56fe\u8868\u63a7\u4ef6&#xff1a;\u9650\u5236\u663e\u793a\u70b9\u6570&#xff08;\u62bd\u7a00\/\u964d\u91c7\u6837&#xff09;&#xff0c;\u4e0d\u8981\u4e00\u4e2a\u4e0d\u6f0f\u5168\u753b\u3002\u8d8b\u52bf\u66f2\u7ebf\u7528&#034;\u62bd\u70b9\u7b97\u6cd5&#034;&#xff08;\u5982 LTTB \u6216\u7b80\u5355\u7684\u7b49\u95f4\u9694\u62bd\u7a00&#xff09;\u628a 10 \u4e07\u70b9\u538b\u5230 2000 \u70b9\u518d\u753b\u3002<\/li>\n<\/ul>\n<p>WPF&#xff1a;<\/p>\n<ul>\n<li>ItemsControl \u52a1\u5fc5\u5f00\u542f\u865a\u62df\u5316&#xff1a;\n<p>&lt;ListBox VirtualizingStackPanel.IsVirtualizing&#061;&#034;True&#034;<br \/>\n         VirtualizingStackPanel.VirtualizationMode&#061;&#034;Recycling&#034;<br \/>\n         ScrollViewer.CanContentScroll&#061;&#034;True&#034;&gt;<\/p>\n<p>\u6ce8\u610f&#xff1a;CanContentScroll&#061;&#034;False&#034;&#xff08;\u50cf\u7d20\u6eda\u52a8&#xff09;\u4f1a\u76f4\u63a5\u7981\u7528\u865a\u62df\u5316&#xff0c;\u8fd9\u662f\u6700\u5e38\u89c1\u7684\u8e29\u5751\u70b9\u3002<\/li>\n<li>\u7ed1\u5b9a\u5927\u6570\u636e\u7528 ObservableCollection \u65f6&#xff0c;\u6279\u91cf\u53d8\u66f4\u7528 AddRange \u98ce\u683c\u7684\u81ea\u5b9a\u4e49\u96c6\u5408&#xff08;\u4e00\u6b21\u6027 Reset \u901a\u77e5&#xff09;&#xff0c;\u907f\u514d N \u6b21\u901a\u77e5 N \u6b21\u5e03\u5c40\u3002<\/li>\n<li>\u9759\u6001\u8d44\u6e90\/\u753b\u5237\u6807\u8bb0 x:Static \u6216 Freeze() \u53ef\u51bb\u7ed3\u5bf9\u8c61\u3002<\/li>\n<li>\u52a8\u753b\u7528 RenderTransform \u800c\u975e\u6539 Margin\/Width&#xff08;\u907f\u514d\u89e6\u53d1\u5e03\u5c40\u91cd\u7b97&#xff09;\u3002<\/li>\n<\/ul>\n<h4>4.6 \u8de8\u7ebf\u7a0b\u66f4\u65b0&#xff1a;\u7528 BeginInvoke&#xff0c;\u5e76\u5408\u5e76<\/h4>\n<p>\/\/ \u274c Invoke \u662f\u540c\u6b65\u963b\u585e&#xff1a;\u540e\u53f0\u7ebf\u7a0b\u8981\u7b49 UI \u5904\u7406\u5b8c\u624d\u7ee7\u7eed<br \/>\nthis.Invoke(new Action(() &#061;&gt; label.Text &#061; v));<\/p>\n<p>\/\/ \u2705 BeginInvoke \u662f\u5f02\u6b65\u6295\u9012&#xff1a;\u540e\u53f0\u7ebf\u7a0b\u6254\u4e0b\u5c31\u8d70<br \/>\nthis.BeginInvoke(new Action(() &#061;&gt; label.Text &#061; v));<\/p>\n<p>\u4f46\u66f4\u91cd\u8981\u7684\u662f\u9891\u7387\u2014\u2014\u5373\u4f7f BeginInvoke&#xff0c;\u6bcf\u79d2\u51e0\u5343\u6b21\u7167\u6837\u628a UI \u961f\u5217\u6491\u7206\u3002\u6240\u4ee5 4.4 \u7684&#034;\u5b9a\u9891\u6279\u91cf&#034;\u662f\u6839\u672c\u89e3\u6cd5&#xff0c;BeginInvoke \u53ea\u662f\u51cf\u5c11\u7b49\u5f85\u3002<\/p>\n<p>\u5224\u65ad\u662f\u5426\u9700\u8981 Invoke&#xff1a;<\/p>\n<p>private void SafeUpdate(Action a)<br \/>\n{<br \/>\n    if (IsHandleCreated &amp;&amp; InvokeRequired) BeginInvoke(a);<br \/>\n    else a();<br \/>\n}<\/p>\n<h4>4.7 GC \u4e0e\u5185\u5b58&#xff1a;\u6d88\u706d&#034;\u5468\u671f\u6027\u987f\u4e00\u4e0b&#034;<\/h4>\n<p>\u5982\u679c\u5361\u987f\u8868\u73b0\u4e3a\u6bcf\u9694\u4e00\u6bb5\u65f6\u95f4\u89c4\u5f8b\u6027\u987f\u4e00\u4e0b&#xff08;\u800c\u4e0d\u662f\u64cd\u4f5c\u67d0\u529f\u80fd\u65f6\u5361&#xff09;&#xff0c;\u5927\u6982\u7387\u662f GC\u3002<\/p>\n<ul>\n<li>\u907f\u514d\u5728\u9ad8\u9891\u5faa\u73af\u91cc new \u5bf9\u8c61&#xff1a;\u7528\u5bf9\u8c61\u6c60 \/ ArrayPool&lt;T&gt;.Shared.Rent() \/ \u590d\u7528\u7f13\u51b2\u533a<\/li>\n<li>\u9ad8\u9891\u6570\u503c\u573a\u666f\u4f18\u5148 struct&#xff08;\u503c\u7c7b\u578b&#xff09;&#xff0c;\u907f\u514d\u88c5\u7bb1<\/li>\n<li>\u5927\u5bf9\u8c61&#xff08;&gt;85KB&#xff09;\u4f1a\u8fdb LOH&#xff0c;\u9891\u7e41\u5206\u914d\u4f1a\u89e6\u53d1\u6602\u8d35\u7684 Gen2 \u56de\u6536<\/li>\n<li>\u5b57\u7b26\u4e32\u62fc\u63a5\u7528 StringBuilder&#xff0c;\u65e5\u5fd7\u522b\u5728\u5faa\u73af\u91cc\u62fc<\/li>\n<li>\u7528 GC.TryStartNoGCRegion&#xff08;\u8c28\u614e\u4f7f\u7528&#xff09;\u4fdd\u62a4\u5173\u952e\u5b9e\u65f6\u6bb5<\/li>\n<\/ul>\n<p>\u6392\u67e5&#xff1a;PerfView \u770b GC \u6682\u505c\u65f6\u95f4&#xff0c;\u6216 AppContext \u6253\u5f00 GC \u65e5\u5fd7\u3002<\/p>\n<h4>4.8 \u6e32\u67d3\u5c42\u4f18\u5316<\/h4>\n<p>WinForms&#xff1a;<\/p>\n<p>\/\/ \u5f00\u542f\u53cc\u7f13\u51b2&#xff0c;\u6d88\u9664\u95ea\u70c1\u4e0e\u53cd\u590d\u64e6\u9664<br \/>\npublic MyControl()<br \/>\n{<br \/>\n    SetStyle(ControlStyles.OptimizedDoubleBuffer |<br \/>\n             ControlStyles.AllPaintingInWmPaint |<br \/>\n             ControlStyles.UserPaint, true);<br \/>\n}<\/p>\n<ul>\n<li>OnPaint \u91cc\u53ea\u753b&#xff0c;\u4e0d\u7b97&#xff1a;\u4f4d\u56fe\u9884\u751f\u6210\u3001\u9884\u7f29\u653e&#xff0c;\u7ed8\u5236\u65f6\u76f4\u63a5 DrawImage<\/li>\n<li>\u65e0\u6548\u533a\u88c1\u526a&#xff1a;Invalidate(rect) \u800c\u975e Invalidate() \u5168\u7a97\u91cd\u7ed8<\/li>\n<\/ul>\n<p>WPF&#xff1a;<\/p>\n<ul>\n<li>\u590d\u6742\u9759\u6001\u89c6\u89c9\u6811\u7528 BitmapCache \u7f13\u5b58<\/li>\n<li>\u80fd\u51bb\u7ed3\u7684 Freezable \u5c31 Freeze()<\/li>\n<li>\u907f\u514d\u5d4c\u5957\u591a\u5c42 Grid \u53cd\u590d\u6d4b\u91cf&#xff1b;\u5e03\u5c40\u6296\u52a8\u65f6\u8003\u8651\u56fa\u5b9a\u5c3a\u5bf8<\/li>\n<li>OpacityMask\u3001\u5927\u9762\u79ef Effect&#xff08;\u5982 DropShadowEffect&#xff09;\u5f88\u8d35&#xff0c;\u80fd\u7701\u5219\u7701<\/li>\n<\/ul>\n<hr \/>\n<h3>\u4e94\u3001\u4e24\u4e2a\u5178\u578b\u6848\u4f8b<\/h3>\n<h4>\u6848\u4f8b A&#xff1a;\u6570\u636e\u91c7\u96c6\u8f6f\u4ef6&#xff0c;\u6bcf\u79d2 5000 \u70b9&#xff0c;\u754c\u9762\u70b9\u4e0d\u52a8<\/h4>\n<p>\u75c7\u72b6&#xff1a;\u63a5\u4e0a PLC \u540e\u754c\u9762\u51e0\u4e4e\u65e0\u6cd5\u64cd\u4f5c&#xff0c;CPU \u5360\u7528 90%&#043;\u3002<\/p>\n<p>\u5b9a\u4f4d&#xff1a;\u770b\u95e8\u72d7\u65e5\u5fd7\u663e\u793a\u6301\u7eed 300~800ms \u7684 STALL\u3002dotTrace \u663e\u793a UI \u7ebf\u7a0b\u88ab\u5927\u91cf Invoke \u8c03\u7528\u6808\u5360\u6ee1\u3002<\/p>\n<p>\u6839\u56e0&#xff1a;\u6bcf\u4e2a\u6570\u636e\u70b9\u56de\u8c03\u91cc this.Invoke() \u66f4\u65b0 Label &#043; \u8ffd\u52a0\u66f2\u7ebf\u70b9&#xff0c;\u7b49\u4e8e\u6bcf\u79d2 5000 \u6b21\u8de8\u7ebf\u7a0b\u6d88\u606f &#043; 5000 \u6b21\u63a7\u4ef6\u91cd\u7ed8 &#043; \u66f2\u7ebf\u70b9\u6570\u65e0\u4e0a\u9650\u589e\u957f\u3002<\/p>\n<p>\u6539\u6cd5&#xff1a;<\/p>\n<li>\u91c7\u96c6\u56de\u8c03\u6539\u4e3a Channel.Writer.TryWrite&#xff0c;\u53ea\u5165\u961f<\/li>\n<li>UI \u4fa7 PeriodicTimer 100ms \u6279\u91cf\u51fa\u5e27<\/li>\n<li>\u66f2\u7ebf\u505a\u62bd\u7a00&#xff0c;\u6700\u591a\u4fdd\u7559 2000 \u4e2a\u663e\u793a\u70b9&#xff0c;\u5386\u53f2\u6570\u636e\u843d\u5e93<\/li>\n<li>\u6570\u503c\u6807\u7b7e\u53ea\u66f4\u65b0\u53ef\u89c1\u533a\u57df&#xff08;\u865a\u62df\u6a21\u5f0f&#xff09;<\/li>\n<p>\u7ed3\u679c&#xff1a;CPU \u964d\u5230 8%&#xff0c;\u754c\u9762\u4e1d\u6ed1\u3002<\/p>\n<h4>\u6848\u4f8b B&#xff1a;\u70b9&#034;\u52a0\u8f7d&#034;\u6309\u94ae\u540e\u5f7b\u5e95\u5047\u6b7b&#xff0c;\u65e0\u62a5\u9519<\/h4>\n<p>\u75c7\u72b6&#xff1a;\u70b9\u51fb\u540e\u754c\u9762\u5b8c\u5168\u65e0\u54cd\u5e94&#xff0c;\u4efb\u52a1\u7ba1\u7406\u5668\u663e\u793a CPU \u5360\u7528\u63a5\u8fd1 0&#xff08;\u5173\u952e\u7ebf\u7d22&#xff1a;CPU \u4e3a 0 \u8bf4\u660e\u4e0d\u662f\u5728\u8ba1\u7b97&#xff0c;\u662f\u5728\u7b49\u5f85&#xff09;\u3002<\/p>\n<p>\u5b9a\u4f4d&#xff1a;CPU \u5360\u7528\u4e3a 0 \u5374\u5361\u6b7b &#061; \u5178\u578b\u6b7b\u9501\u7279\u5f81\u3002<\/p>\n<p>\u6839\u56e0&#xff1a;var data &#061; LoadAsync().Result; \u2014\u2014 UI \u7ebf\u7a0b\u540c\u6b65\u7b49\u5f85&#xff0c;\u800c LoadAsync \u5185\u90e8 await \u540e\u9700\u8981\u56de\u5230 UI \u7ebf\u7a0b\u3002<\/p>\n<p>\u6539\u6cd5&#xff1a;<\/p>\n<li>\u4e8b\u4ef6\u5904\u7406\u5668\u6539 async void&#xff0c;\u5168\u7a0b await<\/li>\n<li>\u670d\u52a1\u5c42\u6240\u6709 await \u8865 .ConfigureAwait(false)<\/li>\n<li>\u52a0\u4e0a\u5168\u5c40\u89c4\u5219\u7981\u6b62 .Result\/.Wait()<\/li>\n<hr \/>\n<h3>\u516d\u3001\u6392\u67e5 Checklist<\/h3>\n<p>\u6309\u8fd9\u4e2a\u987a\u5e8f\u8fc7\u4e00\u904d&#xff0c;\u57fa\u672c\u4e0d\u4f1a\u6f0f&#xff1a;<\/p>\n<ul>\n<li>[ ] \u5148\u91cf\u5316&#xff1a;\u52a0 UI \u5fc3\u8df3\u770b\u95e8\u72d7&#xff0c;\u786e\u8ba4\u5361\u591a\u4e45\u3001\u4ec0\u4e48\u65f6\u5019\u5361<\/li>\n<li>[ ] \u6293\u73b0\u573a&#xff1a;dotTrace \/ VS \u63a2\u67e5\u5668\u770b UI \u7ebf\u7a0b\u4e0a\u6700\u957f\u7684\u90a3\u4e00\u6761\u5b9e\u5fc3\u5757<\/li>\n<li>[ ] \u5168\u5c40\u641c\u200b .Result\u3001.Wait()\u3001.GetAwaiter().GetResult()&#xff0c;\u5168\u90e8\u6539\u6389<\/li>\n<li>[ ] \u5168\u5c40\u641c\u200b UI \u4e8b\u4ef6\u91cc\u7684\u540c\u6b65 IO&#xff1a;\u6570\u636e\u5e93\u3001\u6587\u4ef6\u3001\u7f51\u7edc\u3001\u4e32\u53e3<\/li>\n<li>[ ] \u68c0\u67e5\u670d\u52a1\u5c42\u662f\u5426\u6709 ConfigureAwait(false)<\/li>\n<li>[ ] \u7edf\u8ba1 UI \u66f4\u65b0\u9891\u7387&#xff1a;\u4e00\u79d2\u5185\u66f4\u65b0\u4e86\u591a\u5c11\u6b21&#xff1f;\u8d85\u8fc7 60 \u6b21\u5c31\u8be5\u6279\u91cf\u5316<\/li>\n<li>[ ] \u68c0\u67e5 Invoke \u8c03\u7528\u6b21\u6570&#xff0c;\u6539 BeginInvoke &#043; \u6279\u91cf<\/li>\n<li>[ ] \u5927\u6570\u636e\u5217\u8868&#xff1a;\u662f\u5426\u5f00\u4e86\u865a\u62df\u6a21\u5f0f \/ UI \u865a\u62df\u5316<\/li>\n<li>[ ] DataGridView\/ListView\/TreeView \u6279\u91cf\u64cd\u4f5c\u662f\u5426 BeginUpdate\/SuspendLayout<\/li>\n<li>[ ] \u9ad8\u9891\u4e8b\u4ef6&#xff08;TextChanged\/MouseMove\/Scroll&#xff09;\u662f\u5426\u505a\u4e86\u8282\u6d41\u9632\u6296<\/li>\n<li>[ ] OnPaint \u91cc\u6709\u6ca1\u6709\u505a\u8ba1\u7b97\u3001\u8bfb\u6587\u4ef6\u3001\u7f29\u653e\u4f4d\u56fe<\/li>\n<li>[ ] \u66f2\u7ebf\/\u56fe\u8868\u70b9\u6570\u662f\u5426\u6709\u4e0a\u9650&#xff0c;\u662f\u5426\u62bd\u7a00<\/li>\n<li>[ ] \u9ad8\u9891\u5faa\u73af\u91cc\u662f\u5426\u9891\u7e41 new \u5bf9\u8c61&#xff08;\u770b GC \u6682\u505c&#xff09;<\/li>\n<li>[ ] WinForms \u662f\u5426\u5f00\u4e86\u53cc\u7f13\u51b2&#xff1b;WPF \u662f\u5426\u8bef\u8bbe CanContentScroll&#061;&#034;False&#034;<\/li>\n<li>[ ] \u662f\u5426\u6709\u5168\u91cf\u6570\u636e\u65e0\u8282\u5236\u585e\u8fdb UI&#xff08;\u5206\u9875 \/ \u53ea\u663e\u793a\u53ef\u89c1\u8303\u56f4&#xff09;<\/li>\n<\/ul>\n<hr \/>\n<h3>\u4e03\u3001\u4ec0\u4e48\u65f6\u5019\u8be5\u6362\u67b6\u6784<\/h3>\n<p>\u5982\u679c\u4ee5\u4e0a\u90fd\u505a\u4e86\u4ecd\u7136\u5361&#xff0c;\u8bf4\u660e\u5355\u673a\u5355\u8fdb\u7a0b\u7684\u6a21\u578b\u5df2\u7ecf\u5230\u5934\u4e86&#xff0c;\u8003\u8651&#xff1a;<\/p>\n<li>\u91c7\u96c6\u4e0e\u754c\u9762\u5206\u79bb&#xff1a;\u540e\u53f0\u670d\u52a1&#xff08;Windows Service&#xff09;\u8d1f\u8d23\u91c7\u96c6&#043;\u5165\u5e93&#xff0c;UI \u8fdb\u7a0b\u53ea\u8ba2\u9605\/\u8f6e\u8be2\u5c11\u91cf\u805a\u5408\u6570\u636e\u3002\u5de5\u63a7\u5927\u9879\u76ee\u5f3a\u70c8\u63a8\u8350\u8fd9\u6761\u8def\u3002<\/li>\n<li>\u6570\u636e\u964d\u7ef4&#xff1a;UI \u6c38\u8fdc\u53ea\u663e\u793a&#034;\u5f53\u524d\u9700\u8981\u7684\u90a3\u4e00\u5c4f&#034;&#xff0c;\u5386\u53f2\u67e5\u8be2\u4ea4\u7ed9\u6570\u636e\u5e93\u5206\u9875\u3002<\/li>\n<li>\u6e32\u67d3\u6362\u65b9\u6848&#xff1a;\u6d77\u91cf\u66f2\u7ebf\u8003\u8651\u4e13\u7528\u56fe\u8868\u5e93&#xff08;\u5982 ScottPlot\u3001LiveCharts \u7684\u865a\u62df\u5316\u914d\u7f6e&#xff09;\u6216 DirectX\/GPU \u6e32\u67d3&#xff0c;\u522b\u786c\u625b GDI&#043;\u3002<\/li>\n<li>\u534f\u8bae\u5c42\u4f18\u5316&#xff1a;PLC \u901a\u8baf\u7528\u6279\u91cf\u8bfb\u800c\u975e\u5355\u70b9\u8bfb&#xff0c;\u91c7\u96c6\u5468\u671f\u4e0e UI \u5237\u65b0\u5468\u671f\u5f7b\u5e95\u89e3\u8026\u3002<\/li>\n<hr \/>\n<h3>\u7ed3\u8bed<\/h3>\n<p>\u754c\u9762\u5361\u987f\u8fd9\u4e8b&#xff0c;\u5b9a\u4f4d\u6bd4\u4f18\u5316\u91cd\u8981\u3002\u7edd\u5927\u591a\u6570\u5361\u987f\u4e0d\u9700\u8981\u9ad8\u6df1\u7b97\u6cd5\u2014\u2014\u8981\u4e48\u662f\u91cd\u6d3b\u5e72\u9519\u4e86\u7ebf\u7a0b&#xff0c;\u8981\u4e48\u662f\u6b7b\u9501&#xff0c;\u8981\u4e48\u662f\u5237\u65b0\u592a\u9891\u7e41\u3002\u5148\u7528\u770b\u95e8\u72d7\u628a&#034;\u5361\u591a\u4e45&#034;\u91cf\u5316\u51fa\u6765&#xff0c;\u518d\u7528\u63a2\u67e5\u5668\u6293\u5230\u90a3\u4e00\u6761\u963b\u585e\u6808&#xff0c;\u95ee\u9898\u57fa\u672c\u5c31\u89e3\u51b3\u4e86\u4e00\u534a\u3002<\/p>\n<p>\u8bb0\u4f4f\u4e09\u53e5\u8bdd&#xff1a;<\/p>\n<li>UI \u7ebf\u7a0b\u53ea\u505a\u4e24\u4ef6\u4e8b&#xff1a;\u66f4\u65b0\u63a7\u4ef6\u3001\u5206\u53d1\u547d\u4ee4\u3002<\/li>\n<li>await \u4e00\u8def\u5230\u5e95&#xff0c;\u7edd\u4e0d .Result\u3002<\/li>\n<li>\u540e\u53f0\u591a\u5feb\u90fd\u884c&#xff0c;UI \u5b9a\u9891\u51fa\u5e27\u3002<\/li>\n<\/p>\n<p>\u7801\u5b50\u4e0d\u6613&#xff0c;\u5982\u679c\u60a8\u89c9\u5f97\u6211\u7684\u6587\u7ae0\u5bf9\u60a8\u6709\u5e2e\u52a9\u7684\u8bdd&#xff0c;\u70e6\u8bf7\u60a8\u6253\u8d4f\u4e00\u5143&#xff0c;\u6211\u4e70\u74f6\u6c34\u559d&#xff1b;\u60a8\u7684\u652f\u6301\u5c06\u662f\u6211\u7ee7\u7eed\u5206\u4eab\u7684\u65e0\u9650\u52a8\u529b&#xff0c;\u8c22\u8c22&#xff01;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001\u5148\u7edf\u4e00\u8ba4\u77e5&#xff1a;\u5361\u987f\u5230\u5e95\u662f\u4ec0\u4e48Windows \u684c\u9762\u7a0b\u5e8f\u7684 UI \u6709\u4e00\u4e2a\u94c1\u5f8b&#xff1a;\u53ea\u6709\u4e00\u4e2a UI \u7ebf\u7a0b&#xff0c;\u5b83\u9760\u4e00\u4e2a\u6d88\u606f\u6cf5&#xff08;Message Loop&#xff09;\u6d3b\u7740\u3002\u9f20\u6807\u70b9\u51fb\u3001\u952e\u76d8\u8f93\u5165\u3001\u91cd\u7ed8\u8bf7\u6c42\u3001\u5b9a\u65f6\u5668\u3001Invoke \u56de\u8c03&#xff0c;\u5168\u90fd\u662f\u6392\u8fdb\u8fd9\u4e2a\u961f\u5217\u7684\u4e00\u6761\u6761\u6d88\u606f&#xff0c;UI \u7ebf\u7a0b\u4e00\u6761\u6761\u5904\u7406\u3002\u4e8e\u662f\u7ed3\u8bba\u975e\u5e38\u76f4\u63a5&#xff1a;UI \u7ebf\u7a0b\u4e0a\u4efb\u4f55\u4e00\u6b21\u6267\u884c\u8d85\u8fc7 ~100ms&#xff0c;\u7528\u6237\u5c31\u80fd\u660e\u786e\u611f\u89c9\u5230\\&#8221;\u5361\\&#8221;&amp;#xff<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[55],"topic":[],"class_list":["post-107014","post","type-post","status-publish","format-standard","hentry","category-server","tag-c"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>C# \u754c\u9762\u5361\u987f\uff1a\u4ece\u5b9a\u4f4d\u5230\u6839\u6cbb - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/107014.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"C# \u754c\u9762\u5361\u987f\uff1a\u4ece\u5b9a\u4f4d\u5230\u6839\u6cbb - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u4e00\u3001\u5148\u7edf\u4e00\u8ba4\u77e5&#xff1a;\u5361\u987f\u5230\u5e95\u662f\u4ec0\u4e48Windows \u684c\u9762\u7a0b\u5e8f\u7684 UI \u6709\u4e00\u4e2a\u94c1\u5f8b&#xff1a;\u53ea\u6709\u4e00\u4e2a UI \u7ebf\u7a0b&#xff0c;\u5b83\u9760\u4e00\u4e2a\u6d88\u606f\u6cf5&#xff08;Message Loop&#xff09;\u6d3b\u7740\u3002\u9f20\u6807\u70b9\u51fb\u3001\u952e\u76d8\u8f93\u5165\u3001\u91cd\u7ed8\u8bf7\u6c42\u3001\u5b9a\u65f6\u5668\u3001Invoke \u56de\u8c03&#xff0c;\u5168\u90fd\u662f\u6392\u8fdb\u8fd9\u4e2a\u961f\u5217\u7684\u4e00\u6761\u6761\u6d88\u606f&#xff0c;UI \u7ebf\u7a0b\u4e00\u6761\u6761\u5904\u7406\u3002\u4e8e\u662f\u7ed3\u8bba\u975e\u5e38\u76f4\u63a5&#xff1a;UI \u7ebf\u7a0b\u4e0a\u4efb\u4f55\u4e00\u6b21\u6267\u884c\u8d85\u8fc7 ~100ms&#xff0c;\u7528\u6237\u5c31\u80fd\u660e\u786e\u611f\u89c9\u5230&quot;\u5361&quot;&amp;#xff\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/107014.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-09-18T10:56:38+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/107014.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/107014.html\",\"name\":\"C# \u754c\u9762\u5361\u987f\uff1a\u4ece\u5b9a\u4f4d\u5230\u6839\u6cbb - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-09-18T10:56:38+00:00\",\"dateModified\":\"2026-09-18T10:56:38+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/107014.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/107014.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/107014.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"C# \u754c\u9762\u5361\u987f\uff1a\u4ece\u5b9a\u4f4d\u5230\u6839\u6cbb\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"C# \u754c\u9762\u5361\u987f\uff1a\u4ece\u5b9a\u4f4d\u5230\u6839\u6cbb - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/107014.html","og_locale":"zh_CN","og_type":"article","og_title":"C# \u754c\u9762\u5361\u987f\uff1a\u4ece\u5b9a\u4f4d\u5230\u6839\u6cbb - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u4e00\u3001\u5148\u7edf\u4e00\u8ba4\u77e5&#xff1a;\u5361\u987f\u5230\u5e95\u662f\u4ec0\u4e48Windows \u684c\u9762\u7a0b\u5e8f\u7684 UI \u6709\u4e00\u4e2a\u94c1\u5f8b&#xff1a;\u53ea\u6709\u4e00\u4e2a UI \u7ebf\u7a0b&#xff0c;\u5b83\u9760\u4e00\u4e2a\u6d88\u606f\u6cf5&#xff08;Message Loop&#xff09;\u6d3b\u7740\u3002\u9f20\u6807\u70b9\u51fb\u3001\u952e\u76d8\u8f93\u5165\u3001\u91cd\u7ed8\u8bf7\u6c42\u3001\u5b9a\u65f6\u5668\u3001Invoke \u56de\u8c03&#xff0c;\u5168\u90fd\u662f\u6392\u8fdb\u8fd9\u4e2a\u961f\u5217\u7684\u4e00\u6761\u6761\u6d88\u606f&#xff0c;UI \u7ebf\u7a0b\u4e00\u6761\u6761\u5904\u7406\u3002\u4e8e\u662f\u7ed3\u8bba\u975e\u5e38\u76f4\u63a5&#xff1a;UI \u7ebf\u7a0b\u4e0a\u4efb\u4f55\u4e00\u6b21\u6267\u884c\u8d85\u8fc7 ~100ms&#xff0c;\u7528\u6237\u5c31\u80fd\u660e\u786e\u611f\u89c9\u5230\"\u5361\"&amp;#xff","og_url":"https:\/\/www.wsisp.com\/helps\/107014.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-09-18T10:56:38+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"6 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/107014.html","url":"https:\/\/www.wsisp.com\/helps\/107014.html","name":"C# \u754c\u9762\u5361\u987f\uff1a\u4ece\u5b9a\u4f4d\u5230\u6839\u6cbb - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-09-18T10:56:38+00:00","dateModified":"2026-09-18T10:56:38+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/107014.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/107014.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/107014.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"C# \u754c\u9762\u5361\u987f\uff1a\u4ece\u5b9a\u4f4d\u5230\u6839\u6cbb"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/107014","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=107014"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/107014\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=107014"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=107014"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=107014"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=107014"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}