My app is a target app for sharing and am facing issues when the app is running and the user wants to share content. I can't use a frame from the running application because then i get a "marshalling thread" exception.
The application called an interface that was marshalled for a different thread.\r\n\r\nFailed to initialize the application's root visual
My OnStartAsync
method in App.xaml.cs looks like this.
public override async Task OnStartAsync(StartKind startKind, IActivatedEventArgs args)
{
switch (DetermineStartCause(args))
{
// other cases
case AdditionalKinds.Other:
if (args is ShareTargetActivatedEventArgs)
{
var shareArgs = args as ShareTargetActivatedEventArgs;
if (shareArgs.PreviousExecutionState != ApplicationExecutionState.Running)
{
Uri webUrl = await shareArgs.ShareOperation.Data.GetWebLinkAsync();
Debug.WriteLine(webUrl.AbsoluteUri);
//shareArgs.ShareOperation.ReportStarted();
NavigationService.Navigate(typeof(Views.MainPage), webUrl.AbsoluteUri);
}
else
{
await CoreApplication.Views.First().Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
{
Uri webUrl = await shareArgs.ShareOperation.Data.GetWebLinkAsync();
var nav = NavigationServiceFactory(BackButton.Attach, ExistingContent.Exclude);
Window.Current.Content = new Views.ShareLaunch();
Window.Current.Activate();
});
}
}
break;
}
}
I am not sure how to handle the else condition for ShareTargetActivatedEventArgs
ie the case in which the application is already running. I found a similar question on Stackoverlow but it doesn't use Template10 library. How to handle this scenario using Template10 library.