Passing Async Task functions as a parameter

Some Motivations

If you have programmed Windows Phone or Windows Store apps, you may know about Dispatcher in Windows Phone or CoreDispatcher in Windows Store. In this article I will focus more on Windows Phone implementation, but basically this should be very similar in Windows Store.

In general, those dispatchers are ways to marshal UI interactions from a background context (any context that is not the UI context) to the UI. Trying to directly access (both read and write) any UI control or any view model property that has been bound to a UI control from a background context will trigger an UnauthorizedAccessException. Instead you will have to call Dispatcher.BeginInvoke(Action action) method (or Deployment.Current.Dispatcher.BeginInvoke(Action action) if you are not in a page) and put all the UI accessing codes in the action parameter.

It work perfectly fine until I tried to introduce some async logic inside.

You could do it simply this way:

Read More

Windows.Launch contract failed with error: The app didn’t start

I recently met a problem with my Windows 8 app, when only the splash screen’s image showed up and the app crashed. Even App object is not initialized yet so there’s not much I can do with the debugging tools in Visual Studio.

I tried to check Package.appxmanifest, but nothing seemed strange there. Project properties also looked perfectly ok. So I tried to dig in the Event Logs. A quick look in Microsoft-Windows-TWinUI/Operational log (inside Applications and Services Logs/Microsoft/Windows/Apps) revealed several error logs: “Activation of the app <app name> for the Windows.Launch contract failed with error: The app didn’t start.” but there was no other useful information. Searching on the internet did not help either.

I decided to take a look at the changes from last revision, and l suddenly realized the file app.config was added to the project. I suppose Nuget or VS somehow misunderstood the project type and put the file there for assembly binding, and this file prevented app activation from complete successfully. Removing the file and everything go back to normal.

I have already met the same problem before (and I believe someone has also written about this), but I completely forgot about it, and it cost me so much time. So I decide to write the solution down here, to make sure I can solve the problem faster in the future.