{"id":363,"date":"2017-05-10T03:01:19","date_gmt":"2017-05-09T18:01:19","guid":{"rendered":"http:\/\/marius.main.jp\/software\/blog\/?p=363"},"modified":"2021-04-10T17:16:53","modified_gmt":"2021-04-10T08:16:53","slug":"post-363","status":"publish","type":"post","link":"https:\/\/todosoft.net\/blog\/?p=363","title":{"rendered":"await\/async\u7b49\u306e\u5225\u30b9\u30ec\u30c3\u30c9\u304b\u3089\u30b3\u30f3\u30c8\u30ed\u30fc\u30eb\u306e\u30d7\u30ed\u30d1\u30c6\u30a3\u3092\u5909\u66f4\u3059\u308b"},"content":{"rendered":"\n<p>await\/async\u7b49\u306e\u5225\u30b9\u30ec\u30c3\u30c9\u304b\u3089\u30b3\u30f3\u30c8\u30ed\u30fc\u30eb\u306e\u30d7\u30ed\u30d1\u30c6\u30a3\u3092\u5909\u66f4\u3057\u3088\u3046\u3068\u3059\u308b\u3068\u3001<br>\u30b3\u30f3\u30c8\u30ed\u30fc\u30eb\u306e\u63cf\u753b\u3092\u884c\u3063\u3066\u3044\u308b\u30b9\u30ec\u30c3\u30c9\u3068\u7570\u306a\u308b\u70ba\u3001\u30a8\u30e9\u30fc\u3068\u306a\u308b\u3002<\/p>\n\n\n\n<p>InvokeRequired \u3067\u7570\u306a\u308b\u30b9\u30ec\u30c3\u30c9\u304b\u3089\u306e\u547c\u3073\u51fa\u3057\u304b\u3092\u5224\u5b9a\u3057\u3001<br>\u7570\u306a\u308b\u5834\u5408\u306f&nbsp;Invoke \u3067\u518d\u547c\u3073\u51fa\u3057\u3092\u3059\u308b\u3053\u3068\u3067\u89e3\u6c7a\u3059\u308b\u3002<\/p>\n\n\n\n<!--more-->\n\n\n\n<pre class=\"wp-block-luxe-blocks-syntaxhighlighter line-numbers language-csharp\"><code class=\"language-csharp\">public Form1()\n{\n    InitializeComponent();\n\n    button1.Text = \"Ready\";\n}\n\nprivate async void button1_Click(object sender, EventArgs e)\n{\n    await Task.Run(() =>\n    {\n        SetButtonText(\"OK\");\n    });\n}\n\nprotected delegate void DelegateSetButtonText(string _Text);\n\nprivate void SetButtonText(string _Text)\n{\n    if (this.InvokeRequired == true)\n    {\n        DelegateSetButtonText objDelegate = new DelegateSetButtonText(SetButtonText);\n        this.Invoke(objDelegate, new object[] { _Text });\n    }\n    else\n    {\n        button1.Text = _Text;\n    }\n}<\/code><\/pre>\n\n\n\n<p> \u307e\u305f\u4e0b\u8a18\u306e\u3088\u3046\u306b\u8a18\u8f09\u3059\u308b\u3053\u3068\u3067\u3001\u30e1\u30bd\u30c3\u30c9\u3092\u5206\u3051\u308b\u3053\u3068\u306a\u304f\u3001<br>\u660e\u793a\u7684\u306b\u30e1\u30a4\u30f3\u30b9\u30ec\u30c3\u30c9\u3067\u51e6\u7406\u3092\u884c\u3046\u3053\u3068\u3082\u3067\u304d\u308b\u3002 <\/p>\n\n\n\n<pre class=\"wp-block-luxe-blocks-syntaxhighlighter line-numbers language-csharp\"><code class=\"language-csharp\">public Form1()\n{\n    InitializeComponent();\n\n    button1.Text = \"Ready\";\n}\n\nprivate async void button1_Click(object sender, EventArgs e)\n{\n    await Task.Run(() =>\n    {\n        Invoke((MethodInvoker)(() =>\n        {\n            button1.Text = \"OK\";\n        }));\n    });\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-luxe-blocks-syntaxhighlighter line-numbers language-vbnet\"><code class=\"language-vbnet\">Private Async Function Update_InstructionPartLabel() As Task\n\n\tAwait Task.Run(\n\t\tSub()\n\n\t\t\tMe.Invoke(New MethodInvoker(Sub()\n\t\t\t\tbutton1.Text = \"OK\"\n\t\t\tEnd Sub))\n\n\t\tEnd Sub\n\t)\n\nEnd Function<\/code><\/pre>\n\n\n\n<p>WPF\u306eVM\u3067\u306f\u4e0a\u8a18Invoke\u304c\u4f7f\u7528\u3067\u304d\u306a\u3044\u70ba\u3001\u4e0b\u8a18\u306e\u3088\u3046\u306b\u306a\u308b<\/p>\n\n\n\n<pre class=\"wp-block-luxe-blocks-syntaxhighlighter line-numbers language-csharp\"><code class=\"language-csharp\">System.Windows.Application.Current.Dispatcher.Invoke((Action)(() => {\n    \/\/ \u540c\u671f\u51e6\u7406\n}));<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>await\/async\u7b49\u306e\u5225\u30b9\u30ec\u30c3\u30c9\u304b\u3089\u30b3\u30f3\u30c8\u30ed\u30fc\u30eb\u306e\u30d7\u30ed\u30d1\u30c6\u30a3\u3092\u5909\u66f4\u3057\u3088\u3046\u3068\u3059\u308b\u3068\u3001\u30b3\u30f3\u30c8\u30ed\u30fc\u30eb\u306e\u63cf\u753b\u3092\u884c\u3063\u3066\u3044\u308b\u30b9\u30ec\u30c3\u30c9\u3068\u7570\u306a\u308b\u70ba\u3001\u30a8\u30e9\u30fc\u3068\u306a\u308b\u3002 InvokeRequired \u3067\u7570\u306a\u308b\u30b9\u30ec\u30c3\u30c9\u304b\u3089\u306e\u547c\u3073\u51fa\u3057\u304b\u3092\u5224\u5b9a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19,15],"tags":[],"class_list":["post-363","post","type-post","status-publish","format-standard","hentry","category-c","category-15"],"_links":{"self":[{"href":"https:\/\/todosoft.net\/blog\/index.php?rest_route=\/wp\/v2\/posts\/363","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/todosoft.net\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/todosoft.net\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/todosoft.net\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/todosoft.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=363"}],"version-history":[{"count":7,"href":"https:\/\/todosoft.net\/blog\/index.php?rest_route=\/wp\/v2\/posts\/363\/revisions"}],"predecessor-version":[{"id":855,"href":"https:\/\/todosoft.net\/blog\/index.php?rest_route=\/wp\/v2\/posts\/363\/revisions\/855"}],"wp:attachment":[{"href":"https:\/\/todosoft.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=363"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/todosoft.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=363"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/todosoft.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=363"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}