Wait For Async Task To Complete

Use ManualResetEvent to allow you to wait on your thread with an anync task completes. Global object private ManualResetEvent OurTxIsDone; Constructor OurTxIsDone = new ManualResetEvent(false); Using It In A Method That Does Something Async Example //Inline event handler for the Completed event (We've implemented inline in order to make this method self-contained) MyOtherObjectThatsGoingToDoSomethingAsync.Completed += new EventHandler<SocketAsyncEventArgs>(delegate (object […]

Read More

Async, Await, Task, etc

async A Method declared with async (e.g. public async void MyFucntion(… )  will run asnychronously, which means execution of the Method calling it will continue before it is complete.   Task If you want to force it to be a waiting to complete use ‘Task’ as its return type (e.g. public async Task MyFucntion(… )   […]

Read More

Update UI From Background Thread

Calling A Method On The UI Thread async void SomethingHappened() { await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { this.textBlock.Text = “Failure capturing video.”; }); } Set New Screen Page From Other Threads async void SetMainScreenPage(int Page) { await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { 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: […]

Read More

Run a task on a background thread

You can’t create a background thread for a task, but you can schedule it via a static RunAsync method on the Windows.System.Threading.ThreadPool class. Create a high priority thread that runs forever

Read More

.Threads General

Thread Types Universal apps have the following types of threads: UI threads Typcailly an app has a single UI thread, because an app typically has a single window (if there are multiple windows then each will have its own thread). UI threads should be kept free to handle input and update the UI – long […]

Read More