{"id":446,"date":"2007-08-06T12:08:10","date_gmt":"2007-08-06T04:08:10","guid":{"rendered":"http:\/\/fdream.net\/blog\/article\/446.aspx"},"modified":"2007-08-08T13:08:25","modified_gmt":"2007-08-08T05:08:25","slug":"WPF%e4%b8%ad%e7%9a%84%e5%ae%9a%e6%97%b6%e5%99%a8%e7%b1%bb","status":"publish","type":"post","link":"https:\/\/fdream.net\/blog\/article\/446","title":{"rendered":"WPF\u4e2d\u7684\u5b9a\u65f6\u5668\u7c7b"},"content":{"rendered":"<p>\u521a\u5f00\u59cb\u63a5\u89e6WPF\u4e0d\u4e45\uff0c\u4e5f\u662f\u7b2c\u4e00\u6b21\u5c1d\u8bd5\u5f00\u59cb\u5199C#\uff0c\u5199\u5b9a\u65f6\u5668\u7684\u65f6\u5019\u4ee5\u4e3aC#\u4e2dSystem.Timer\u4e2d\u7684Timer\u7c7b\uff0c\u7ed3\u679c\u53d1\u73b0\u8001\u662f\u629b\u51fa\u4e2a\u5f88\u5947\u602a\u7684\u5f02\u5e38\uff1a<\/p>\n<blockquote>\n<p>The calling thread cannot access this object because a different thread owns it.<\/p>\n<\/blockquote>\n<p>\u540e\u6765\u624d\u53d1\u73b0\uff0c\u5176\u5b9eWPF\u662f\u6709\u81ea\u5df1\u7684\u5b9a\u65f6\u5668\u7c7b\u7684\uff0c\u90a3\u5c31\u662fSystem.Windows.Threading\u4e2d\u7684Timer\u7c7b\uff0c\u4f7f\u7528\u8d77\u6765\u4e5f\u5f88\u7b80\u5355\uff1a<\/p>\n<blockquote>\n<p>\/\/\u6784\u9020\u4e00\u4e2aDispatcherTimer\u7c7b\u5b9e\u4f8b<br \/>DispatcherTimer dTimer = new System.Windows.Threading.DispatcherTimer();<\/p>\n<p>\/\/\u8bbe\u7f6e\u4e8b\u4ef6\u5904\u7406\u51fd\u6570<br \/>dTimer.Tick += new EventHandler(dTimer_Tick);<\/p>\n<p>\/\/\u5b9a\u65f6\u5668\u65f6\u95f4\u95f4\u96941s<br \/>dTimer.Interval = new TimeSpan(0,0,1);<\/p>\n<p>\/\/\u542f\u52a8\u5b9a\u65f6\u5668<br \/>dTimer.Start();<\/p>\n<\/blockquote>\n<p>\u5728\u4e0a\u4f8b\u4e2d\uff0c\u4e5f\u53ef\u4ee5\u4f7f\u7528dTimer.IsEnabled = true;\u6765\u542f\u52a8\u5b9a\u65f6\u5668\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u521a\u5f00\u59cb\u63a5\u89e6WPF\u4e0d\u4e45\uff0c\u4e5f\u662f\u7b2c\u4e00\u6b21\u5c1d\u8bd5\u5f00\u59cb\u5199C#\uff0c\u5199\u5b9a\u65f6\u5668\u7684\u65f6\u5019\u4ee5\u4e3aC#\u4e2dSystem.Timer\u4e2d\u7684Timer\u7c7b\uff0c\u7ed3\u679c\u53d1\u73b0\u8001\u662f\u629b\u51fa\u4e2a\u5f88\u5947\u602a\u7684\u5f02\u5e38\uff1a The calling thread cannot access this object because a different thread owns it. \u540e\u6765\u624d\u53d1\u73b0\uff0c\u5176\u5b9eWPF\u662f\u6709\u81ea\u5df1\u7684\u5b9a\u65f6\u5668\u7c7b\u7684\uff0c\u90a3\u5c31\u662fSystem.Windows.Threading\u4e2d\u7684Timer\u7c7b\uff0c\u4f7f\u7528\u8d77\u6765\u4e5f\u5f88\u7b80\u5355\uff1a \/\/\u6784\u9020\u4e00\u4e2aDispatcherTimer\u7c7b\u5b9e\u4f8bDispatcherTimer dTimer = new System.Windows.Threading.DispatcherTimer(); \/\/\u8bbe\u7f6e\u4e8b\u4ef6\u5904\u7406\u51fd\u6570dTimer.Tick += new EventHandler(dTimer_Tick); \/\/\u5b9a\u65f6\u5668\u65f6\u95f4\u95f4\u96941sdTimer.Interval = new TimeSpan(0,0,1); \/\/\u542f\u52a8\u5b9a\u65f6\u5668dTimer.Start(); \u5728\u4e0a\u4f8b\u4e2d\uff0c\u4e5f\u53ef\u4ee5\u4f7f\u7528dTimer.IsEnabled = true;\u6765\u542f\u52a8\u5b9a\u65f6\u5668\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[293],"class_list":["post-446","post","type-post","status-publish","format-standard","hentry","category-coding","tag-WPF"],"views":34895,"_links":{"self":[{"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/posts\/446","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/comments?post=446"}],"version-history":[{"count":0,"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/posts\/446\/revisions"}],"wp:attachment":[{"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/media?parent=446"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/categories?post=446"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/tags?post=446"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}