{"id":3451,"date":"2018-07-12T12:11:42","date_gmt":"2018-07-12T03:11:42","guid":{"rendered":"http:\/\/soundengine.jp\/wordpress\/tips\/?p=3451"},"modified":"2018-07-12T12:11:42","modified_gmt":"2018-07-12T03:11:42","slug":"c%e3%81%ae%e3%82%bf%e3%82%a4%e3%83%9e%e3%83%bc%e3%81%ae%e7%b2%be%e5%ba%a6%e3%81%a8%e3%82%bf%e3%82%a4%e3%83%9e%e3%83%bc%e5%86%85%e3%81%8b%e3%82%89%e3%81%ae%e3%82%b3%e3%83%b3%e3%83%88%e3%83%ad%e3%83%bc","status":"publish","type":"post","link":"https:\/\/soundengine.jp\/wordpress\/tips\/try\/3451\/","title":{"rendered":"C#\u306e\u30bf\u30a4\u30de\u30fc\u306e\u7cbe\u5ea6\u3068\u30bf\u30a4\u30de\u30fc\u5185\u304b\u3089\u306e\u30b3\u30f3\u30c8\u30ed\u30fc\u30eb\u66f4\u65b0"},"content":{"rendered":"<p>\u300c<a href=\"http:\/\/takachan.hatenablog.com\/entry\/2017\/09\/09\/225342\">C#\u306e4\u3064\u306eTimer\u306e\u7528\u9014\u3068\u4f7f\u3044\u65b9<\/a>\u300d\u306b\u3088\u308b\u3068\u3001C#\u306b\u306f\u30bf\u30a4\u30de\u30fc\u304c4\u3064\u3042\u308b\u3089\u3057\u3044\u3002\u3067\u3001System.Timers.Timer\u3092\u4f7f\u3046\u306e\u304c\u3044\u3044\u3093\u3058\u3083\u306a\u3044\u3068\u3044\u3046\u3053\u3068\u3060\u304c\u3001\u305d\u306e\u7cbe\u5ea6\u306f\u3069\u306e\u3050\u3089\u3044\u3042\u308b\u306e\u304b\u8abf\u3079\u3066\u307f\u3088\u3046\u304b\u3068\u3084\u3063\u3066\u307f\u305f\u3002<\/p>\n<p><!--more--><\/p>\n<p>\u3068\u308a\u3042\u3048\u305a\u3067\u304d\u305f\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u304c\u3053\u308c\u30021msec\u306e\u30bf\u30a4\u30de\u30fc\u3092\u4f5c\u6210\u3057\u3001\u305d\u3053\u3067\u30b9\u30c8\u30c3\u30d7\u30a6\u30a9\u30c3\u30c1\u3067\u6e2c\u5b9a\u3057\u305f\u7d50\u679c\u3092\u30ea\u30b9\u30c8\u306b\u5165\u308c\u308b\u3068\u3044\u3046\u3082\u306e\u3002<\/p>\n<pre class=\"lang:c# decode:true \">\r\npublic partial class Form1 : Form\r\n{\r\n\tSystem.Timers.Timer timer = new System.Timers.Timer();\r\n\tStopwatch stopwatch = new Stopwatch();\r\n\r\n\tpublic Form1()\r\n\t{\r\n\t\tInitializeComponent();\r\n\r\n\t\ttimer.Interval = 1;\r\n\t\ttimer.Elapsed += new ElapsedEventHandler(MyClock);\r\n\r\n\t\ttimer.Start();\r\n\t}\r\n\r\n\tpublic void MyClock(object sender, ElapsedEventArgs e)\r\n\t{\r\n\t\tvar text = String.Format(\"{0}\",stopwatch.ElapsedMilliseconds);\r\n\t\tthis.BeginInvoke((Action)(() =&gt; { listBox1.Items.Add(text); }));\r\n\r\n\t\tstopwatch.Restart();\r\n\t}\r\n}<\/pre>\n<h2>C#\u306e\u30bf\u30a4\u30de\u30fc\u306e\u7cbe\u5ea6<\/h2>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/soundengine.jp\/wordpress\/tips\/files\/2018\/07\/20180712_2.png\" alt=\"\" width=\"279\" height=\"482\" class=\"alignnone size-full wp-image-3452\" srcset=\"https:\/\/soundengine.jp\/wordpress\/tips\/files\/2018\/07\/20180712_2.png 279w, https:\/\/soundengine.jp\/wordpress\/tips\/files\/2018\/07\/20180712_2-174x300.png 174w\" sizes=\"auto, (max-width: 279px) 100vw, 279px\" \/><\/p>\n<p>\u7d50\u679c\u7684\u306b\u306f\u300114\uff5e16 msec\u3042\u305f\u308a\u3057\u304b\u51fa\u3066\u306a\u3044\u611f\u3058\u3060\u3002<\/p>\n<p>\u300c<a href=\"http:\/\/takachan.hatenablog.com\/entry\/2017\/03\/30\/005432\">C#\u306eSystem.Threading.Timer\u30af\u30e9\u30b9\u306e\u7cbe\u5ea6\u3092\u78ba\u8a8d\u3059\u308b<\/a>\u300d\u306b\u3088\u308b\u3068\u3001<\/p>\n<blockquote><p>HAL\u306f\u5468\u671f\u304c16ms(\u30cf\u30fc\u30c9\u306b\u3088\u3063\u3066\u306f10ms\u3068\u304b\u3082\u3042\u308b)\u3068\u306a\u3063\u3066\u3044\u3066\u3001\u305d\u306e\u4ed5\u7d44\u307f\u4e0a\u306b\u4e57\u3063\u3066\u3044\u308b(\u3068\u601d\u308f\u308c\u308b)C#\u306e\u30bf\u30a4\u30de\u30fc\u306e\u7cbe\u5ea6\u306f\u524d\u8ff0\u306e\u6570\u5024\u306b\u4f9d\u5b58\u3059\u308b\u304b\u306a\u3068\u3002<\/p><\/blockquote>\n<p>\u3068\u306e\u3053\u3068\u3002Windows API\u7684\u306b\u306f\u3001WaitableTimer\u3092\u4f7f\u3063\u305f\u308atimeBeginPeriod\u305f\u308a\u3067\u3001\u3069\u3046\u3084\u30891msec\u3068\u304b\u306e\u30bf\u30a4\u30de\u30fc\u3082\u3067\u304d\u308b\u3088\u3046\u3060\u3002<\/p>\n<h2>\u30bf\u30a4\u30de\u30fc\u5185\u304b\u3089\u306e\u30b3\u30f3\u30c8\u30ed\u30fc\u30eb\u66f4\u65b0<\/h2>\n<p>\u30bf\u30a4\u30de\u30fc\u5185\u304b\u3089BeginInvoke\u3092\u4f7f\u308f\u305a\u306b\u76f4\u63a5\u30ea\u30b9\u30c8\u306b\u8ffd\u52a0\u3057\u3088\u3046\u3068\u3059\u308b\u3068\u3001<\/p>\n<blockquote><p>\nSystem.InvalidOperationException: &#8216;\u6709\u52b9\u3067\u306f\u306a\u3044\u30b9\u30ec\u30c3\u30c9\u9593\u306e\u64cd\u4f5c: \u30b3\u30f3\u30c8\u30ed\u30fc\u30eb\u304c\u4f5c\u6210\u3055\u308c\u305f\u30b9\u30ec\u30c3\u30c9\u4ee5\u5916\u306e\u30b9\u30ec\u30c3\u30c9\u304b\u3089\u30b3\u30f3\u30c8\u30ed\u30fc\u30eb &#8216;listBox1&#8242; \u304c\u30a2\u30af\u30bb\u30b9\u3055\u308c\u307e\u3057\u305f\u3002&#8217;\n<\/p><\/blockquote>\n<p>\u306a\u3093\u3066\u30a8\u30e9\u30fc\u304c\u51fa\u308b\u3002Invoke\u3067\u30e1\u30a4\u30f3\u30b9\u30ec\u30c3\u30c9\u3067\u51e6\u7406\u3057\u306a\u3044\u3068\u3044\u3051\u306a\u3044\u3088\u3046\u3060\u3002\u3061\u306a\u307f\u306b\u3001BeginInvoke\u3092Invoke\u306b\u3059\u308b\u3068\u7d42\u4e86\u6642\u306b<\/p>\n<blockquote><p>System.ObjectDisposedException: &#8216;\u7834\u68c4\u3055\u308c\u305f\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306b\u30a2\u30af\u30bb\u30b9\u3067\u304d\u307e\u305b\u3093\u3002<br \/>\n\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u540d &#8216;Form1&#8242; \u3067\u3059\u3002&#8217;<\/p><\/blockquote>\n<p>\u3068\u3044\u3046\u30a8\u30e9\u30fc\u304c\u51fa\u308b\u3002Invoke\u9014\u4e2d\u3067Form\u304c\u7d42\u4e86\u3059\u308b\u305f\u3081\u306b\u3001\u884c\u304d\u5834\u304c\u306a\u304f\u306a\u308b\u306e\u3060\u308d\u3046\u304b\u3002\uff08\u305d\u306e\u70b9\u3001BeginInvoke\u306a\u3089\u3001\u52dd\u624b\u306b\u30ad\u30e3\u30f3\u30bb\u30eb\u3055\u308c\u308b\uff1f\u306e\u3067\u554f\u984c\u306a\u3044\u306e\u3060\u308d\u3046\u304b\u3001\u7d30\u304b\u304f\u306f\u3088\u304f\u308f\u304b\u3063\u3066\u3044\u306a\u3044\uff09<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u300cC#\u306e4\u3064\u306eTimer\u306e\u7528\u9014\u3068\u4f7f\u3044\u65b9\u300d\u306b\u3088\u308b\u3068\u3001C#\u306b\u306f\u30bf\u30a4\u30de\u30fc\u304c4\u3064\u3042\u308b\u3089\u3057 &hellip; <a href=\"https:\/\/soundengine.jp\/wordpress\/tips\/try\/3451\/\">\u7d9a\u304d\u3092\u8aad\u3080 <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[33,34],"class_list":["post-3451","post","type-post","status-publish","format-standard","hentry","category-try","tag-c","tag-34"],"_links":{"self":[{"href":"https:\/\/soundengine.jp\/wordpress\/tips\/wp-json\/wp\/v2\/posts\/3451","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/soundengine.jp\/wordpress\/tips\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/soundengine.jp\/wordpress\/tips\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/soundengine.jp\/wordpress\/tips\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/soundengine.jp\/wordpress\/tips\/wp-json\/wp\/v2\/comments?post=3451"}],"version-history":[{"count":1,"href":"https:\/\/soundengine.jp\/wordpress\/tips\/wp-json\/wp\/v2\/posts\/3451\/revisions"}],"predecessor-version":[{"id":3453,"href":"https:\/\/soundengine.jp\/wordpress\/tips\/wp-json\/wp\/v2\/posts\/3451\/revisions\/3453"}],"wp:attachment":[{"href":"https:\/\/soundengine.jp\/wordpress\/tips\/wp-json\/wp\/v2\/media?parent=3451"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/soundengine.jp\/wordpress\/tips\/wp-json\/wp\/v2\/categories?post=3451"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/soundengine.jp\/wordpress\/tips\/wp-json\/wp\/v2\/tags?post=3451"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}