{"id":629,"date":"2016-11-18T15:08:18","date_gmt":"2016-11-18T15:08:18","guid":{"rendered":"https:\/\/ibex.tech\/windows-iot\/?p=89"},"modified":"2016-11-18T15:08:18","modified_gmt":"2016-11-18T15:08:18","slug":"update-ui-from-background-thread","status":"publish","type":"post","link":"https:\/\/ibex.tech\/csharp\/uwp-programming-in-c\/windows-and-pages\/update-ui-from-background-thread","title":{"rendered":"Update UI From Background Thread"},"content":{"rendered":"<h4>\n\tCalling A Method On The UI Thread<\/h4>\n<pre><code>\n\tasync void SomethingHappened()\n\t{\n\t\tawait Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =&gt;\n\t\t{\n\t\t\tthis.textBlock.Text = \"Failure capturing video.\";\n\t\t});\n\t}\n<\/code><\/pre>\n<h4>\n\tSet New Screen Page From Other Threads<\/h4>\n<pre><code>\n\tasync void SetMainScreenPage(int Page)\n\t{\n\t\tawait Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =&gt;\n\t\t{\n\t\t\tWindows.UI.Xaml.Controls.Frame rootFrame = Windows.UI.Xaml.Window.Current.Content as Windows.UI.Xaml.Controls.Frame;\n\t\t\tswitch (Page)\n\t\t\t{\n\t\t\tcase 1:\n\t\t\t\trootFrame.Navigate(typeof(MainPage));\n\t\t\t\tbreak;\n\n\t\t\tcase 2:\n\t\t\t\trootFrame.Navigate(typeof(PageTestIo));\n\t\t\t\tbreak;\n\n\t\t\tcase 3:\n\t\t\t\trootFrame.Navigate(typeof(PageEngineerConfig));\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t});\n\t}\n<\/code><\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Calling A Method On The UI Thread async void SomethingHappened() { await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =&gt; { this.textBlock.Text = &#8220;Failure capturing video.&#8221;; }); } Set New Screen Page From Other Threads async void SetMainScreenPage(int Page) { await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =&gt; { Windows.UI.Xaml.Controls.Frame rootFrame = Windows.UI.Xaml.Window.Current.Content as Windows.UI.Xaml.Controls.Frame; switch (Page) { case 1: rootFrame.Navigate(typeof(MainPage)); break; case 2: [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[69,67],"tags":[],"class_list":["post-629","post","type-post","status-publish","format-standard","hentry","category-threads","category-windows-and-pages"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/posts\/629","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/comments?post=629"}],"version-history":[{"count":0,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/posts\/629\/revisions"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/media?parent=629"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/categories?post=629"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/tags?post=629"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}