{"id":130,"date":"2013-02-10T05:51:29","date_gmt":"2013-02-09T21:51:29","guid":{"rendered":"http:\/\/bohu.net\/blog\/?p=130"},"modified":"2023-02-11T00:56:52","modified_gmt":"2023-02-10T16:56:52","slug":"aaaaaa","status":"publish","type":"post","link":"https:\/\/www.bohu.net\/blog\/130\/","title":{"rendered":"C#  \u591a\u7ebf\u7a0b\u64cd\u4f5c\u6574\u7406 (System.Threading)"},"content":{"rendered":"<h2><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-9546 size-medium\" src=\"https:\/\/bohu.net\/blog\/wp-content\/uploads\/2013\/02\/csharplogo-300x300-300x300.png\" alt=\"\" width=\"300\" height=\"300\" srcset=\"https:\/\/www.bohu.net\/blog\/wp-content\/uploads\/2013\/02\/csharplogo-300x300.png 300w, https:\/\/www.bohu.net\/blog\/wp-content\/uploads\/2013\/02\/csharplogo-300x300-150x150.png 150w\" sizes=\"auto, (max-width: 300px) 85vw, 300px\" \/><\/h2>\n<h2>Thread \u7c7b<\/h2>\n<h4>\u521b\u5efa\u5e76\u63a7\u5236\u7ebf\u7a0b\uff0c\u8bbe\u7f6e\u5176\u4f18\u5148\u7ea7\u5e76\u83b7\u53d6\u5176\u72b6\u6001\u3002<\/h4>\n<p><b>\u547d\u540d\u7a7a\u95f4:<\/b>System.Threading <b>\u7a0b\u5e8f\u96c6:<\/b>mscorlib\uff08\u5728 mscorlib.dll \u4e2d\uff09<\/p>\n<h2>\u6982\u8ff0\u4e0e\u6982\u5ff5<\/h2>\n<p>C#\u652f\u6301\u901a\u8fc7\u591a\u7ebf\u7a0b\u5e76\u884c\u5730\u6267\u884c\u4ee3\u7801\uff0c\u4e00\u4e2a\u7ebf\u7a0b\u6709\u5b83\u72ec\u7acb\u7684\u6267\u884c\u8def\u5f84\uff0c\u80fd\u591f\u4e0e\u5176\u5b83\u7684\u7ebf\u7a0b\u540c\u65f6\u5730\u8fd0\u884c\u3002\u4e00\u4e2aC#\u7a0b\u5e8f\u5f00\u59cb\u4e8e\u4e00\u4e2a\u5355\u7ebf\u7a0b\uff0c\u8fd9\u4e2a\u5355\u7ebf\u7a0b\u662f\u88abCLR\u548c\u64cd\u4f5c\u7cfb\u7edf\uff08\u4e5f\u79f0\u4e3a\u201c\u4e3b\u7ebf\u7a0b\u201d\uff09\u81ea\u52a8\u521b\u5efa\u7684\uff0c\u5e76\u5177\u6709\u591a\u7ebf\u7a0b\u521b\u5efa\u989d\u5916\u7684\u7ebf\u7a0b\u3002<\/p>\n<p>1.\u4f7f\u7528\u7ebf\u7a0b\u7684\u60c5\u51b5<\/p>\n<ul>\n<li>\u2460.\u7a0b\u5e8f\u9700\u8981\u6267\u884c\u548c\u4e24\u4e2a\u548c\u591a\u4e2a\u4efb\u52a1<\/li>\n<li>\u2461.\u7a0b\u5e8f\u8981\u7b49\u5f85\u67d0\u4e8b\u4ef6\u7684\u53d1\u751f\uff1a\u4f8b\u5982\u7528\u6237\u8f93\u5165\u3001\u6587\u4ef6\u64cd\u4f5c\u3001\u7f51\u7edc\u64cd\u4f5c\u548c\u641c\u7d22<\/li>\n<li>\u2462.\u540e\u53f0\u7a0b\u5e8f<\/li>\n<\/ul>\n<p>2.\u591a\u7ebf\u7a0b\u7684\u5e76\u53d1\u6267\u884c \u5982\u679c\u6709\u591a\u4e2a\u7ebf\u7a0b\u5728\u6267\u884c\uff0c\u5355CPU\u53ea\u6709\u4e00\u4e2a\uff0c\u5230\u5e95\u6267\u884c\u7684\u54ea\u4e2a\uff1f<\/p>\n<ul>\n<li>\u2460.\u5982\u679c\u4e00\u4e2a\u7ebf\u7a0b\u8fde\u7eed\u5360\u7528CPU\u8d44\u6e90\u65f6\u95f4\u8fc7\u957f\uff0c\u5176\u5b83\u7684\u8d44\u6e90\u5f97\u4e0d\u5230\u6267\u884c\uff0c \u00a0\u00a0\u00a0\u00a0 \u5219\u7cfb\u7edf\u4f1a\u5f3a\u5236\u7684\u5207\u6362\u6267\u884c\u5176\u5b83\u7ebf\u7a0b\u3002\uff08\u5f3a\u5236\u5265\u593a\uff09<\/li>\n<li>\u2461.\u5982\u679c\u4e00\u4e2a\u7ebf\u7a0b\u6ca1\u4e8b\u53ef\u505a\u3001CPU\u53ef\u6267\u884c\u5176\u5b83\u7ebf\u7a0b\u3002\uff08\u4e3b\u52a8\u653e\u5f03\uff09<\/li>\n<li>\u2462.\u8fd9\u662f\u7531\u64cd\u4f5c\u7cfb\u7edf\u7684\u8c03\u5ea6\u673a\u5236\u51b3\u5b9a\u7684\uff0c\u4e0d\u540c\u7684\u64cd\u4f5c\u7cfb\u7edf\u8c03\u5ea6\u673a\u5236\u4e0d\u4e00\u6837\u3002 \u00a0\u00a0 \u4e00\u822c\u65e0\u6cd5\u7cbe\u786e\u7684\u9884\u6599\u591a\u7ebf\u7a0b\u7684\u6267\u884c\u987a\u5e8f\uff0c\u5728\u7a0b\u5e8f\u8bbe\u8ba1\u7684\u65f6\u5019\u5e94\u7279\u522b\u6ce8\u610f<\/li>\n<\/ul>\n<p>3.\u521b\u5efa\u5e76\u542f\u52a8\u7ebf\u7a0b<\/p>\n<p>ThreadStart \u7ebf\u7a0b\u542f\u52a8\u59d4\u6258\u540d=new ThreadStart(\u65b9\u6cd5\u540d);<\/p>\n<p>Thread \u7ebf\u7a0b\u5b9e\u4f8b\u540d=new Thread(\u7ebf\u7a0b\u542f\u52a8\u59d4\u6258\u540d); \u7ebf\u7a0b\u5b9e\u4f8b\u540d.Start();<\/p>\n<p>4.\u7ec8\u6b62\u7ebf\u7a0b<\/p>\n<ul>\n<li>\u2460.\u7ebf\u7a0b\u5b9e\u4f8b\u540d.Abort();\u7528\u6b64\u65b9\u6cd5\u7684\u540e\u679c\u662f\u4e0d\u53ef\u6062\u590d\u7684\u7ec8\u6b62\u7ebf\u7a0b\u3002<\/li>\n<li>\u2461.\u7ebf\u7a0b\u5b9e\u4f8b\u540d.Interrupt();\u4e2d\u65ad\u540e\u53ef\u6062\u590d<\/li>\n<\/ul>\n<p>5.\u4f11\u7720\u7ebf\u7a0b<\/p>\n<ul>\n<li>\u2460.\u7ebf\u7a0b\u5b9e\u4f8b\u540d.Sleep(); \u00a0\u00a0\u00a0 \u5f53\u7ebf\u7a0bSleep\u65f6\uff0c\u7cfb\u7edf\u5c31\u7acb\u5373\u9000\u51fa\u6267\u884c\u961f\u5217\u4e00\u6bb5\u65f6\u95f4\uff0c\u5f53\u7761\u7720\u7ed3\u675f\u65f6\uff0c\u7cfb\u7edf\u4f1a\u4ea7\u751f\u4e00\u4e2a\u65f6\u949f\u4e2d\u65ad\uff0c\u4ece\u800c \u00a0\u00a0\u00a0 \u4f7f\u7ebf\u7a0b\u56de\u5230\u6267\u884c\u961f\u5217\u4e2d\uff0c\u4ece\u800c\u6062\u590d\u7ebf\u7a0b\u7684\u6267\u884c\u3002<\/li>\n<\/ul>\n<p>6.\u6302\u8d77\/\u6062\u590d\u7ebf\u7a0b<\/p>\n<ul>\n<li>\u2460.\u7ebf\u7a0b\u5b9e\u4f8b\u540d.Suspend();\u6302\u8d77 \u00a0\u00a0\u00a0 \u4e0e\u7ebf\u7a0b\u4f11\u7720\u4e0d\u540c\uff0c\u7ebf\u7a0b\u7684\u6302\u8d77\u4e0d\u4f1a\u4f7f\u7ebf\u7a0b\u7acb\u5373\u505c\u6b62\u6267\u884c\uff0c\u76f4\u5230\u7ebf\u7a0b\u5230\u8fbe\u5b89\u5168\u70b9\u4e4b\u540e\u5b83\u624d\u53ef\u4ee5\u5c06\u8be5\u7ebf\u7a0b\u6302\u8d77\uff0c\u5982\u679c\u7ebf\u7a0b\u5c1a\u672a\u542f\u52a8\u6216\u5df2\u7ecf\u505c\u6b62\uff0c\u5219\u5b83\u5c06\u4e0d\u80fd\u6302\u8d77\u3002<\/li>\n<li>\u2461.\u7ebf\u7a0b\u5b9e\u4f8b\u540d.Resume();\u6062\u590d \u00a0\u00a0\u00a0\u00a0 \u5c06\u4f7f\u4e00\u4e2a\u7ebf\u7a0b\u8df3\u51fa\u6302\u8d77\u72b6\u6001\u5e76\u4f7f\u8be5\u7ebf\u7a0b\u7ee7\u7eed\u6267\u884c\u3002 \u00a0\u00a0\u00a0 \u4e00\u4e2a\u7ebf\u7a0b\u4e0d\u80fd\u5bf9\u53e6\u4e00\u4e2a\u7ebf\u7a0b\u8c03\u7528Sleep() \uff0c\u4f46\u662f\u4e00\u4e2a\u7ebf\u7a0b\u53ef\u4ee5\u5bf9\u53e6\u4e00\u4e2a\u7ebf\u7a0b\u8c03\u7528Suspend()\u3002 \u00a0\u00a0\u00a0 \u8fd8\u53ef\u4ee5\u4f7f\u7528\u8bb8\u591a\u5176\u5b83\u7684\u65b9\u5f0f\u6765\u963b\u585e\u7ebf\u7a0b\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u901a\u8fc7\u8c03\u7528 Thread.Join \u4f7f\u4e00\u4e2a\u7ebf\u7a0b\u7b49\u5f85\u53e6\u4e00\u4e2a\u7ebf\u7a0b \uff08\u5b50\u7ebf\u7a0b\uff09\u505c\u6b62\u3002\u4f7f\u7528Monitor.Wait\u4f7f\u4e00\u4e2a\u7ebf\u7a0b\u7b49\u5f85\u8bbf\u95ee\u4e00\u4e2a\u540c\u6b65\u5bf9\u8c61\u3002<\/li>\n<\/ul>\n<p>7.\u4e32\u884c\u5316\u7ebf\u7a0b<\/p>\n<ul>\n<li>\u2460.\u7ebf\u7a0b\u5b9e\u4f8b\u540d.jion(); \u00a0\u00a0\u00a0 \u4f8b\u5982\u5728\u4e3b\u7ebf\u7a0b\u4e2d\u63d2\u5165t.jion(); \u00a0\u00a0\u00a0\u00a0 \u4e3b\u7ebf\u7a0b\u6267\u884c\u5230\u8fd9\u6761\u8bed\u53e5\u540e\uff0c\u4e3b\u7ebf\u7a0b\uff08\u5f53\u524d\u7ebf\u7a0b\uff09\u7acb\u5373\u8fdb\u5165\u963b\u585e\u72b6\u6001.\u76f4\u5230t\u8fd0\u884c\u5b8c\u540e\u963b\u585e\u72b6\u6001\u624d\u89e3\u9664\u3002\u76f8\u5f53\u4e8e\u628at\u7684\u4efb\u52a1\u63d2\u5165\u6216\u4e32\u8054\u5230\u4e3b\u7ebf\u7a0b\u4e2d,\u628a\u4e24\u6761\u7ebf\u7d22\u4e32\u8054\u6210\u4e00\u6761\u7ebf\u7d22<\/li>\n<\/ul>\n<p>8.\u7ebf\u7a0b\u7684\u9501\u5b9a\u673a\u5236 \u7ebf\u7a0b\u7684\u9501\u5b9a\u673a\u5236\u53ef\u4ee5\u4fdd\u8bc1\u6bcf\u6b21\u53ea\u6709\u4e00\u4e2a\u7ebf\u7a0b\u53ef\u4ee5\u8bbf\u95ee\u5171\u4eab\u8d44\u6e90\u3002 \u4f7f\u7528\u5173\u952e\u5b57lock<\/p>\n<ul>\n<li>\u2460.lock\u8bed\u53e5\u7684\u8bed\u6cd5 \u00a0\u00a0\u00a0\u00a0 lock(\u5bf9\u8c61\u5f15\u7528)\u8bed\u53e5\u5757\uff1b<\/li>\n<li>\u2461.lock\u8bed\u53e5\u7684\u529f\u80fd \u00a0\u00a0\u00a0\u00a0 \u5f53\u5bf9\u8c61\u88ablock \u9501\u5b9a\u65f6\uff0c\u8bbf\u95ee\u8be5\u7ebf\u7a0b\u7684\u5176\u5b83\u7ebf\u7a0b\u4f1a\u8fdb\u5165\u7b49\u5f85\u7684\u72b6\u6001\u3002<\/li>\n<li>\u2462.\u5bf9\u8c61\u9501\u673a\u5236\u4fdd\u8bc1\u4e86\u5bf9\u8c61\u8bbf\u95ee\u7684\u5b8c\u6574\u6027\uff1a\u53ea\u6709\u4e00\u4e2a\u7ebf\u7a0b\u5b8c\u6210\u64cd\u4f5c\u540e\uff0c\u5176\u5b83\u7684\u7ebf\u7a0b\u624d\u80fd\u8fdb\u884c\u64cd\u4f5c\u3002<\/li>\n<li>\u2463.\u4e00\u822c\u60c5\u51b5\u4e0b\uff0c\u5f53\u4e00\u4e2a\u7ebf\u7a0b\u5199\u67d0\u4e2a\u53d8\u91cf\uff0c\u800c\u540c\u65f6\u53ef\u80fd\u6709\u5176\u5b83\u7684\u7ebf\u7a0b\u8bfb\u6216\u5199\u8fd9\u4e2a\u53d8\u91cf\u65f6\uff0c\u4e3a\u4e86\u4fdd\u6301\u6570\u636e\u7684\u4e00\u00a0\u81f4\u6027\u5e94\u8be5\u4f7f\u7528\u9501\u5b9a\u673a\u5236\u3002<\/li>\n<li>\u2464.\u7ebf\u7a0b\u7684\u5b89\u5168\u6027 \u00a0\u00a0\u00a0\u00a0 \u7ebf\u7a0b\u5b89\u5168\u6027\u5c31\u662f\u4fdd\u62a4\u7684\u7c7b\u7684\u6210\u5458\u548c\u4ee3\u7801\u7684\u5b89\u5168\uff0c\u4ece\u800c\u4f7f\u4ed6\u4eec\u4e0d\u4f1a\u540c\u65f6\u88ab\u51e0\u4e2a\u7ebf\u7a0b\u4e2d\u65ad\uff0c\u4f7f\u7528\u9501\u5b9a\u673a\u5236\u3002<\/li>\n<li>\u2465.\u591a\u7ebf\u7a0b\u516c\u7528\u4e00\u4e2a\u5bf9\u8c61\u65f6\uff0c\u5c31\u4e0d\u5e94\u8be5\u4f7f\u7528lock\u5173\u952e\u5b57\u4e86\uff0c\u8fd9\u91ccMonitor\uff0cMonitor\u63d0\u4f9b\u4e86\u4f7f\u7ebf\u7a0b\u5171\u4eab\u8d44\u6e90\u7684\u65b9 \u6848\u3002 Monitor\u7c7b\u53ef\u4ee5\u9501\u5b9a\u4e00\u4e2a\u5bf9\u8c61\uff0c\u4e00\u4e2a\u7ebf\u7a0b\u53ea\u6709\u5f97\u5230\u8fd9\u628a\u9501\u624d\u53ef\u4ee5\u5bf9\u8be5\u5bf9\u8c61\u8fdb\u884c\u64cd\u4f5c\u3002 \u5982\uff1a Monitor.Enter(obj);<br \/>\nMonitor.Exit(obj);<\/li>\n<li>\u2466.\u4e34\u754c\u533a\u548c\u9501 \u5f53\u8c08\u8bba\u591a\u7ebf\u7a0b\u5e94\u7528\u7a0b\u5e8f\u7684\u65f6\u5019\uff0c\u9996\u5148\u5e94\u8be5\u60f3\u5230\u7684\u5c31\u662f\u5e76\u53d1\u6027\u95ee\u9898\u3002\u5c3d\u7ba1\u8fd9\u5bf9\u4e8e\u540c\u65f6\u6267\u884c\u591a\u4e2a\u4efb\u52a1\u7684\u7a0b\u5e8f\u662f\u5f88\u6709\u7528\u7684\uff0c\u4f46\u901a\u5e38\u90fd\u662f\u5371\u9669\u7684\u3002\u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u5728C#\u4e2d\u63d0\u51fa\u4e86\u4e34\u754c\u533a\u548c\u9501\u7684\u6982\u5ff5\u3002\u5728\u7a0b\u5e8f\u8bbe\u8ba1\u4e2d\uff0c\u4e34\u754c\u533a\u662f\u4e00\u5757\u5728\u4efb\u4f55\u65f6\u5019\u53ea\u80fd\u6709\u4e00\u4e2a\u8fdb\u7a0b\u8fdb\u5165\u7684\u533a\u57df\u3002\u5728C#\u4e2d\u901a\u8fc7\u8bed\u53e5lock\u6765\u58f0\u660e\u4e34\u754c\u533a\u3002lock\u58f0\u660e\u540e\u9762\u7684\u4ee3\u7801\uff0c\u4e0d\u7ba1\u662f\u4ee5\u884c\u8fd8\u662f\u4e00\u5757\u4ee3\u7801\uff0c\u5728\u540c\u4e00\u65f6\u95f4\u6700\u591a\u53ea\u80fd\u6709\u4e00\u4e2a\u8fdb\u7a0b\u6267\u884c\u3002<\/li>\n<\/ul>\n<p>9.\u7ebf\u7a0b\u7684\u4f18\u5148\u7ea7\u5177\u6709\u4e0d\u53ef\u9760\u6027,\u5c31\u662f\u8bf4\u4e0d\u80fd\u7528\u4f18\u5148\u7ea7\u6765\u63a7\u5236\u7ebf\u7a0b\u7684\u6267\u884c\u987a\u5e8f\u3002<\/p>\n<p>10.\u540e\u53f0\u7ebf\u7a0b<\/p>\n<ul>\n<li>\u2460.\u4ec0\u4e48\u662f\u540e\u53f0\u7ebf\u7a0b\uff1f\u6bd4\u8d77\u5e94\u7528\u7a0b\u5e8f\u7684\u4e3b\u56fe\u5f62\u7528\u6237\u754c\u9762\uff08GUI\uff09\u7ebf\u7a0b\u6765\u8bf4\uff0c\u8fd9\u4e9b\u7ebf\u7a0b\u4ee5\u8f83\u4f4e\u7684\u4f18\u5148\u6743\u5728\u4e0d\u540c\u7684\u8fc7\u7a0b\u4e2d\u8fd0\u884c\u7740\u3002\u5bf9\u4e8e\u4e0d\u80fd\u7acb\u5373\u6267\u884c\u7ed3\u675f\uff0c \u53c8\u4e0d\u60f3\u4e00\u76f4\u7b49\u5f85\u7684\u4efb\u52a1\uff0c\u540e\u53f0\u7ebf\u7a0b\u80fd\u5f88\u597d\u7684\u80dc\u4efb\u3002\u5728C#\u4e2d\uff0c\u628a\u7ebf\u7a0b\u5bf9\u8c61\u7684\u00a0\u00a0IsBackground\u5c5e\u6027\u8bbe\u4e3atrue\uff0c\u8be5\u7ebf\u7a0b\u5373\u4e3a\u540e\u53f0\u7ebf\u7a0b\u3002 \u00a0\u00a0 \u540e\u53f0\u7ebf\u7a0b\u8ddf\u524d\u53f0\u7ebf\u7a0b\u53ea\u6709\u4e00\u4e2a\u533a\u522b\uff0c\u90a3\u5c31\u662f\u540e\u53f0\u7ebf\u7a0b\u4e0d\u59a8\u788d\u7a0b\u5e8f\u7684\u7ec8\u6b62\u3002\u4e00\u65e6\u4e00\u4e2a\u8fdb\u7a0b\u6240\u6709\u7684\u524d\u53f0\u7ebf\u7a0b\u90fd\u7ec8\u6b62\u540e\uff0cCLR\u5c06\u901a\u8fc7\u8c03\u7528\u4efb\u610f\u4e00\u4e2a\u5b58\u6d3b\u4e2d\u7684\u540e\u53f0\u8fdb\u7a0b\u7684Abort()\u65b9\u6cd5\u6765\u5f7b\u5e95\u7ec8\u6b62\u8fdb\u7a0b\u3002\u6ce8\u610f\uff1a\u540e\u53f0\u7ebf\u7a0b\u4e0d\u80fd\u76f4\u63a5\u64cd\u4f5c\u6240\u5728\u8fdb\u7a0b\u4e4b\u5916\u7684\u6570\u636e\u5f15\u7528\u3002<\/li>\n<li>\u2461.\u600e\u6837\u4e0e\u540e\u53f0\u7ebf\u7a0b\u901a\u8baf\uff1f\u8fd0\u7528MethodInvoker\u59d4\u6d3e\u5b9e\u4f53\u3002\u4e5f\u53ef\u5728\u521d\u59cb\u5316\uff08\u6784\u9020\u51fd\u6570\uff09\u4e2d\u52a0\u5165\u4e0b\u9762\u4e00\u53e5\u5373\u53ef\u5b9e\u73b0\u901a\u8baf\uff1a<\/li>\n<\/ul>\n<p>Control.CheckForIllegalCrossThreadCalls = False;<\/p>\n<p>\u8981\u4f7f\u7528MethodInvoker\u59d4\u6d3e\uff0c\u9700\u8981\u4e09\u4e2a\u6761\u4ef6\uff1a<\/p>\n<ul>\n<li>\u3000\u3000a.\u4e00\u4e2a\u521b\u5efa\u59d4\u6d3e\u7684\u540e\u53f0\u7ebf\u7a0b<\/li>\n<\/ul>\n<pre class=\"brush:csharp\">Thread thread=new Thread(new ThreadStart(Run));\n\nthread.IsBackground=true;  \/\/\u628aThread\u8bbe\u4e3a\u540e\u53f0\u7ebf\u7a0b\n\nthread.Start();<\/pre>\n<ul>\n<li>\u3000\u3000b.\u4e00\u4e2a\u7528\u4f5c\u540e\u53f0\u7ebf\u7a0b\u4e0e\u524d\u53f0\u53ef\u89c6\u5316\u5355\u5143\u7684\u63a5\u53e3\u7684\u7c7b\u7ea7\u65b9\u6cd5<\/li>\n<\/ul>\n<pre class=\"brush:csharp\"> public void Run()\n        {\n            int count = 0;\n            try\n            {\n                MethodInvoker mi = new MethodInvoker(this.UpdateLabel);\n                \/\/\u521b\u5efa\u4e00\u4e2a\u59d4\u6258\uff0cUpdateLabel\u662f\u8be5\u59d4\u6258\u6240\u6258\u7ba1\u7684\u4ee3\u7801\uff0c\u5fc5\u987b\u662f\u58f0\u660e\u4e3avoid \u4e14\u4e0d\u63a5\u53d7\u4efb\u4f55\u53c2\u6570\u7684\u4efb\u4f55\u65b9\u6cd5\u3002\n                while (true)\n                {\n                    count++;\n                    \/\/this.Invoke(mi);\/\/\u540c\u6b65\u6267\u884c\u59d4\u6258\n                    this.BeginInvoke(mi);\/\/\u5f02\u6b65\u6267\u884c\u59d4\u6258\n                    Thread.Sleep(500);\n                }\n            }\n            catch (ThreadInterruptedException e)\n            {\n                Console.WriteLine(\"Interruption Exception in Thread:{0}\", e);\n            }\n            catch (Exception ex)\n            {\n                Console.WriteLine(\"Exception in Thread:{0}\", ex);\n            }\n        }<\/pre>\n<ul>\n<li>\u3000\u3000c.\u4e00\u4e2a\u5e94\u7528\u7a0b\u5e8f\u4e2d\u53ef\u4ee5\u66f4\u65b0\u7684\u53ef\u89c6\u5316\u5355\u5143<\/li>\n<\/ul>\n<pre class=\"brush:csharp\">public void UpdateLabel()\n{ \u3000\u3000\u3000\u3000\n    label1.Text=count.ToString(); \u3000\u3000\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Thread \u7c7b \u521b\u5efa\u5e76\u63a7\u5236\u7ebf\u7a0b\uff0c\u8bbe\u7f6e\u5176\u4f18\u5148\u7ea7\u5e76\u83b7\u53d6\u5176\u72b6\u6001\u3002 \u547d\u540d\u7a7a\u95f4:System.Threading \u7a0b\u5e8f &hellip; <a href=\"https:\/\/www.bohu.net\/blog\/130\/\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">\u201cC#  \u591a\u7ebf\u7a0b\u64cd\u4f5c\u6574\u7406 (System.Threading)\u201d<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":136,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,4,12,23,26],"tags":[98,179,369,378,459,496,532,616],"class_list":["post-130","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-net","category-c-net","category-windows","category-23","category-26","tag-c","tag-gui","tag-system-threading","tag-thread","tag-459","tag-496","tag-532","tag-616"],"_links":{"self":[{"href":"https:\/\/www.bohu.net\/blog\/wp-json\/wp\/v2\/posts\/130","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.bohu.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bohu.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bohu.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bohu.net\/blog\/wp-json\/wp\/v2\/comments?post=130"}],"version-history":[{"count":1,"href":"https:\/\/www.bohu.net\/blog\/wp-json\/wp\/v2\/posts\/130\/revisions"}],"predecessor-version":[{"id":9869,"href":"https:\/\/www.bohu.net\/blog\/wp-json\/wp\/v2\/posts\/130\/revisions\/9869"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.bohu.net\/blog\/wp-json\/"}],"wp:attachment":[{"href":"https:\/\/www.bohu.net\/blog\/wp-json\/wp\/v2\/media?parent=130"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bohu.net\/blog\/wp-json\/wp\/v2\/categories?post=130"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bohu.net\/blog\/wp-json\/wp\/v2\/tags?post=130"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}