1
Vote

hresult: 0x8001010e (rpc_e_wrong_thread) in Navigate

description

Hi all,
I am working on an Windows 8 App which should act as share target.
For that I implemented the following code apps.xaml.cs:
       protected override async void OnShareTargetActivated(ShareTargetActivatedEventArgs args)
        {

            args.ShareOperation.ReportStarted();
            IReadOnlyList<IStorageItem> f = await args.ShareOperation.Data.GetStorageItemsAsync();

            string token = StorageApplicationPermissions.FutureAccessList.Add(f[0]);
            args.ShareOperation.ReportDataRetrieved();
            ShareHelper.ShareOperation = args.ShareOperation;
            ShareHelper.FileToken = token;
            NavigationService.Navigate("ShareTarget", null);
        }
This resulted in following exeption

The application called an interface That was marshalled for a different thread. (Exception from HRESULT: 0x8001010E (RPC_E_WRONG_THREAD))

at Windows.UI.Xaml.Controls.Frame.Navigate(Type sourcePageType, Object parameter)
at Microsoft.Practices.Prism.StoreApps.FrameFacadeAdapter.Navigate(Type sourcePageType, Object parameter)
at Microsoft.Practices.Prism.StoreApps.FrameNavigationService.Navigate(String pageToken, Object parameter)
at VerifySignatur.App.<OnShareTargetActivated>d__13.MoveNext()

Google did not show useful results.
Does anyone have some glue how to fix that?
Josef

comments

GOstrowsky wrote Apr 24 at 6:58 PM

Hi Josef,

Based on my understanding, the issue remain on trying to navigate on a different thread from the UI Thread. Inside the async method, you would need to call Navigation by invoking the Dispatcher in order to return to the UI Thread.

Replacing the Navigate statement withe the following one should resolve the problem:

Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                      {
                            NavigationService.Navigate("ShareTarget", null);
                      });
I hope this helped,
Regards.

Gabriel Ostrowsky
https://blogs.southworks.net/gostrowsky