{"id":871,"date":"2021-09-14T13:00:46","date_gmt":"2021-09-14T05:00:46","guid":{"rendered":"http:\/\/www.wayln.com\/?p=871"},"modified":"2021-09-14T13:00:46","modified_gmt":"2021-09-14T05:00:46","slug":"system-reactive%e5%9f%ba%e7%a1%80-%e9%80%9a%e8%bf%87%e8%8a%82%e6%b5%81%e5%92%8c%e9%87%87%e6%a0%b7%e6%8e%a7%e5%88%b6%e4%ba%8b%e4%bb%b6%e6%b5%81","status":"publish","type":"post","link":"https:\/\/www.wayln.com\/?p=871","title":{"rendered":"System.Reactive\u57fa\u7840\u2014\u2014\u901a\u8fc7\u8282\u6d41\u548c\u91c7\u6837\u63a7\u5236\u4e8b\u4ef6\u6d41"},"content":{"rendered":"<div id=\"toc_container\" class=\"toc_transparent no_bullets\"><p class=\"toc_title\">Contents<\/p><ul class=\"toc_list\"><li><a href=\"#i\"><span class=\"toc_number toc_depth_1\">1<\/span> \u95ee\u9898<\/a><\/li><li><a href=\"#i-2\"><span class=\"toc_number toc_depth_1\">2<\/span> \u89e3\u51b3\u65b9\u6848<\/a><\/li><li><a href=\"#i-3\"><span class=\"toc_number toc_depth_1\">3<\/span> \u8ba8\u8bba<\/a><\/li><\/ul><\/div>\n<h1><span id=\"i\">\u95ee\u9898<\/span><\/h1>\n<p>\u5728\u7f16\u5199\u54cd\u5e94\u5f0f\u4ee3\u7801\u65f6\uff0c\u65f6\u95f4\u4f20\u5165\u8fc7\u5feb\u662f\u5e38\u89c1\u7684\u95ee\u9898\uff0c\u4f46\u662f\u9ad8\u901f\u8fd0\u884c\u7684\u4e8b\u4ef6\u6d41\u4f1a\u4f7f\u7a0b\u5e8f\u4e0d\u582a\u91cd\u8d1f\u3002<\/p>\n<h1><span id=\"i-2\">\u89e3\u51b3\u65b9\u6848<\/span><\/h1>\n<p>\u4e3a\u4e86\u5e94\u4ed8\u4e8b\u4ef6\u6570\u636e\u7684\u6d2a\u6d41\uff0cSystem.Reactive\u63d0\u4f9b\u4e86\u4e13\u95e8\u7684\u8fd0\u7b97\u7b26\u3002Throttle\uff08\u8282\u6d41\uff09\u548cSample\uff08\u91c7\u6837\uff09\u63d0\u4f9b\u4e86\u4e24\u79cd\u201c\u9a6f\u5316\u201d\u9ad8\u901f\u8f93\u5165\u4e8b\u4ef6\u7684\u9014\u5f84<br \/>\nThrottle\u8fd0\u7b97\u7b26\u521b\u5efa\u4e00\u4e2a\u6ed1\u52a8\u7684\u8d85\u65f6\u7a97\u53e3\u3002\u5f53\u4e8b\u4ef6\u5230\u8fbe\u65f6\uff0c\u5b83\u4f1a\u91cd\u7f6e\u8d85\u65f6\u7a97\u53e3\u3002\u5f53\u8d85\u65f6\u7a97\u53e3\u8fc7\u671f\u65f6\uff0c\u5b83\u4f1a\u53d1\u5e03\u6700\u540e\u4e00\u4e2a\u5230\u8fbe\u7a97\u53e3\u7684\u4e8b\u4ef6\u503c\u3002<\/p>\n<p>\u4e0b\u9762\u7684\u793a\u4f8b\u76d1\u542c\u9f20\u6807\u79fb\u52a8\uff0c\u5f53\u4e14\u4ec5\u5f53\u9f20\u6807\u9759\u6b62\u6574\u65741\u79d2\u540e\uff0c\u624d\u901a\u8fc7Throttle\u8fd0\u7b97\u7b26\u6c47\u62a5\u66f4\u65b0\uff1a<\/p>\n<pre><code class=\"language-CSharp line-numbers\">private void button8_Click(object sender, EventArgs e)\n{\n            Observable.FromEventPattern&lt;MouseEventHandler, MouseEventArgs&gt;(\n                handler =&gt; (s, a) =&gt; handler(s, a), handler =&gt; MouseMove += handler, handler =&gt; MouseMove -= handler\n                ).Select(x =&gt; x.EventArgs.GetPosition(this)).Throttle(TimeSpan.FromSeconds(1)).Subscribe(x =&gt; Trace.WriteLine(\n                    $\"{DateTime.Now.Second};Saw{x.X + x.Y}\"));\n}\n<\/code><\/pre>\n<p>Throttle\u8fd0\u7b97\u7b26\u5e38\u5e38\u7528\u5728\u7c7b\u4f3c\u81ea\u52a8\u586b\u5145\u7684\u60c5\u51b5\u4e0b\uff0c\u57fa\u5f53\u7528\u6237\u6b63\u5728\u6587\u672c\u6846\u5185\u8f93\u5165\u6587\u5b57\u65f6\uff0c\u5e0c\u671b\u5728\u7528\u6237\u505c\u4e0b\u6765\u4e4b\u524d\u5c31\u8fdb\u884c\u5b9e\u9645\u7684\u67e5\u8be2\u3002<br \/>\nSample\u7684\u5de5\u4f5c\u65b9\u5f0f\u6709\u6240\u4e0d\u540c\u3002\u4ed6\u521b\u5efa\u4e00\u4e2a\u5e38\u89c4\u7684\u8d85\u65f6\u65f6\u6bb5\uff0c\u5e76\u5728\u6bcf\u6b21\u8d85\u65f6\u8fc7\u671f\u65f6\uff0c\u53d1\u5e03\u8be5\u7a97\u53e3\u5185\u6700\u8fd1\u7684\u503c\u3002\u5982\u679c\u5728\u91c7\u6837\u65f6\u6bb5\u5185\u672a\u80fd\u6536\u5230\u503c\uff0c\u5219\u4e0d\u4f1a\u53d1\u5e03\u8be5\u65f6\u6bb5\u7684\u4efb\u4f55\u7ed3\u679c\u3002<br \/>\n\u4e0b\u9762\u7684\u793a\u4f8b\u6355\u83b7\u9f20\u6807\u79fb\u52a8\u5e76\u4ee51\u79d2\u4e3a\u95f4\u9694\u5bf9\u79fb\u52a8\u8fdb\u884c\u91c7\u6837\uff0c\u548cThrottle\u793a\u4f8b\u4e0d\u540c\uff0cSample\u793a\u4f8b\u5e76\u4e0d\u9700\u8981\u901a\u8fc7\u9759\u6b62\u9f20\u6807\u6765\u67e5\u770b\u6570\u636e\uff1a<\/p>\n<pre><code class=\"language-CSharp line-numbers\"> Observable.FromEventPattern&lt;MouseEventHandler, MouseEventArgs&gt;(\n                handler =&gt; (s, a) =&gt; handler(s, a), handler =&gt; MouseMove += handler, handler =&gt; MouseMove -= handler).Select(x =&gt; x.EventArgs.Location).Sample(TimeSpan.FromSeconds(1)).Subscribe(x =&gt; Trace.WriteLine($\"{DateTime.Now.Second};Saw {x.X + x.Y}\"));\n\n<\/code><\/pre>\n<h1><span id=\"i-3\">\u8ba8\u8bba<\/span><\/h1>\n<p>\u5bf9\u201c\u9a6f\u5316\u201d\u6d77\u91cf\u7684\u8f93\u5165\u800c\u8a00\uff0c\u8282\u6d41\u548c\u91c7\u6837\u90fd\u662f\u5fc5\u8981\u7684\u5de5\u5177\uff0c\u522b\u5fd8\u4e86\uff0c\u901a\u8fc7\u6807\u51c6LINQ Where\u8fd0\u7b97\u7b26\uff0c\u8fd8\u80fd\u8f7b\u677e\u5730\u8fdb\u884c\u8fc7\u6ee4\u3002\u4e0d\u59a8\u628aThrottle\u548cSample\u770b\u4f5c\u4e0eWhere\u7c7b\u4f3c\u7684\u8fd0\u7b97\u7b26\uff0c\u53ea\u4e0d\u8fc7\u8fd9\u4e24\u8005\u6839\u636e\u65f6\u95f4\u7a97\u53e3\u800c\u4e0d\u662f\u4e8b\u4ef6\u6570\u636e\u6267\u884c\u8fc7\u6ee4\u3002\u8fd9\u4e09\u79cd\u8fd0\u7b97\u7b26\u90fd\u80fd\u4e00\u4e2a\u5b57\u7684\u65b9\u5f0f\u201c\u9a6f\u5316&#8221;\u9ad8\u901f\u7684\u8f93\u5165\u6d41\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Contents1 \u95ee\u98982 \u89e3\u51b3\u65b9\u68483 \u8ba8\u8bba \u95ee\u9898 \u5728\u7f16\u5199\u54cd\u5e94\u5f0f\u4ee3\u7801\u65f6\uff0c\u65f6\u95f4\u4f20\u5165\u8fc7\u5feb\u662f\u5e38\u89c1\u7684\u95ee\u9898\uff0c\u4f46\u662f\u9ad8\u901f\u8fd0\u884c [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,41,2],"tags":[],"class_list":["post-871","post","type-post","status-publish","format-standard","hentry","category-c","category-41","category-2"],"_links":{"self":[{"href":"https:\/\/www.wayln.com\/index.php?rest_route=\/wp\/v2\/posts\/871","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wayln.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wayln.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wayln.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wayln.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=871"}],"version-history":[{"count":1,"href":"https:\/\/www.wayln.com\/index.php?rest_route=\/wp\/v2\/posts\/871\/revisions"}],"predecessor-version":[{"id":872,"href":"https:\/\/www.wayln.com\/index.php?rest_route=\/wp\/v2\/posts\/871\/revisions\/872"}],"wp:attachment":[{"href":"https:\/\/www.wayln.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=871"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wayln.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=871"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wayln.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=871"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}