[WinRT] Receiving a File from Share Charm

Topics: Getting Started
Jan 26, 2013 at 2:41 PM
Edited Jan 26, 2013 at 2:42 PM

Hi @all,

I've implemented  a share target which uses a WCF call to retrieve a file. The should be able to save the resulting file. However share charm does not Support filepicker. So I store the file temporary in ApplicationData.Current.LocalFolder and restart the App by using protocol contract an the filename as Parameter. In my App.xaml.cs I implemented OnActivated, prepare parameters for MainViewModel and do a DisplayRootViewFor(MainViewModel). There I want to reuse the filesave Methode. When calling this method an exception is thrown:

System.Exception wurde nicht behandelt.
  HResult=-2144730623
  Message=Der Vorgang kann nicht beendet werden, da das Fenster geschlossen wird. (Ausnahme von HRESULT: 0x802A0201)
  Source=Windows.UI
  StackTrace:
       at Windows.UI.Core.CoreDispatcher.RunAsync(CoreDispatcherPriority priority, DispatchedHandler agileCallback)
       at System.Threading.WinRTSynchronizationContext.Post(SendOrPostCallback d, Object state)
       at System.Threading.Tasks.SynchronizationContextAwaitTaskContinuation.PostAction(Object state)
       at System.Threading.Tasks.AwaitTaskContinuation.RunCallback(ContextCallback callback, Object state, Task& currentTask)
    --- End of stack trace from previous location where exception was thrown ---
       at System.Threading.Tasks.AwaitTaskContinuation.b__1(Object s)
       at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(Object state)
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
       at System.Threading.ThreadPoolWorkQueue.Dispatch()
       at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()
  InnerException: 

I believe I'm doing something wrong. I suspect that I messed up with async/await. but I could not figure out how to solve it. Does anyone have an idea?