locked
[UWP]Terminating application when Share Charm is call RRS feed

  • Question

  • Hi,

    I have a problem. I'm trying to share photo, to do that I'm using DataTransferManager and DataRequested. When I've connected phone with PC and build application directly from VS2015 (OS is Windows 10) and I'm clicking button with share action, then Share charm is appear and work correctly. Problem is, when I stop debugging, and start application directly from phon, then when I'm clicking share button, share charm is appearing, and after 3-5 seconds whole application terminated.

    I created new empty project and copied exactly the same code like at first application, and it working correctly at both cases.

    What can cause, that at bigger project with many views the same code don't working correctly, and at vanilla application it working pretty correctly?

    private void button_Click(object sender, RoutedEventArgs e)
            {
                DataTransferManager dataTransferManager = DataTransferManager.GetForCurrentView();
    
                dataTransferManager.DataRequested += new TypedEventHandler<DataTransferManager, DataRequestedEventArgs>(this.OnDataTransferManager_DataRequested);
                DataTransferManager.ShowShareUI();
            }
    
    
            private void OnDataTransferManager_DataRequested(DataTransferManager sender, DataRequestedEventArgs args)
            {
                try
                {
                    DataRequest request = args.Request;
    
                    request.Data.Properties.Title = "Share Example";
                    request.Data.Properties.Description = "A demonstration on how to share";
                    request.Data.SetDataProvider(StandardDataFormats.StorageItems, OnDeferredFileRequested);
                    request.Data.SetDataProvider(StandardDataFormats.Text, OnDeferredFileRequestedV2);
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine(ex.Message);
                }
            }
    
            protected void OnDeferredFileRequestedV2(DataProviderRequest request)
            {
                try
                {
                    DataProviderDeferral deferral = request.GetDeferral();
    
                    request.SetData("Test text.");
                    deferral.Complete();
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine(ex.Message);
                }
            }
    
    
            protected async void OnDeferredFileRequested(DataProviderRequest request)
            {
                try
                {
                    DataProviderDeferral deferral = request.GetDeferral();
    
                   	// await Task.Delay(500);   
    		var pictureList = await KnownFolders.PicturesLibrary.GetFileAsync("photoName.png");
                    request.SetData(new[] { pictureList });
                    deferral.Complete();
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine(ex.Message);
                }
            }



    • Edited by Nevendar Friday, November 27, 2015 9:11 AM
    • Edited by Xavier Xie-MSFT Monday, December 7, 2015 10:46 AM edit title
    Thursday, November 26, 2015 2:56 PM

Answers

  • Problem solved. One line of code was sufficient.

    After take a photo, and save on the phone, we should dispose MediaCapture object.

    Apparently Windows Phone 10 do it automatically in contrast to WP8.1, so application work correct (or better memory management).

    Thank You for all suggestions.

    Wednesday, December 9, 2015 9:34 AM

All replies

  • Hi Nevendar,

    Sorry for my late reply.

    I have checked the document about “DataTransferManager”: https://msdn.microsoft.com/en-us/library/windows/apps/xaml/windows.applicationmodel.datatransfer.datatransfermanager.aspx

    You might need to notice the “note” in document, it shows “This class is not agile, which means that you need to consider its threading model and marshaling behavior”.

    So you might need to try to use “Dispatcher” for “ShowShareUI” method.

    await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal,()=> {
                    DataTransferManager.ShowShareUI();
                });

    And you could also see there’re two requirements in document: “introduced version 10.0.10240.0” and minimum supported windows phone 8.

    So you need to check your phone OS version, if its OS version was earlier than “10.0.10240.0”, you might need to update it.

    If you have any other concern regarding this issue, please feel free to let me know.

    Best Regards,

    Xavier Eoro


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, November 30, 2015 7:14 AM
  • @Xavier Thank for Your explaination, but Yout suggestion unfortunately dosn't work.

    When I running application directly from VS on Debug or Release is working perfect. But when I'm trying from phones always occur terminating of application after 3-5 sek by sharring is started.

    I'm testing it on two phones with Windows Phone 8.1. I have a problem with Windows Phone 10. I can not build any application from VS to phone with WP10, there appear a bootstrap connecting error.

    Application working perfect also at emulators (WP8.1 and WP10).


    • Edited by Nevendar Tuesday, December 1, 2015 11:30 AM
    Tuesday, December 1, 2015 11:16 AM
  • Hi Nevendar,

    >>” But when I'm trying from phones always occur terminating of application after 3-5 sek by sharring is started.”

    You could refer to this UWP code sample for details: https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/ShareSource, and test this sample on your device. Because I have made a code sample in the past like you have done. It worked well on my lumia phone. If this sample also can’t work on your device, I supposed that this issue was more related to your OS environment.  

    >>” I have a problem with Windows Phone 10. I can not build any application from VS to phone with WP10, there appear a bootstrap connecting error.”

    Visual studio 2015 Update1 is available now. Please check this link: https://www.visualstudio.com/news/vs2015-update1-vs

    If you have not updated it, you need to upgrade.

    Best Regards,

    Xavier Eoro


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Wednesday, December 2, 2015 2:22 AM
  • Hi Xavier,

    >> "You could refer to this UWP code sample for details: https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/ShareSource, and test this sample on your device. Because I have made a code sample in the past like you have done. It worked well on my lumia phone. If this sample also can’t work on your device, I supposed that this issue was more related to your OS environment."

    I will try it, thank You.

    Thank You a lot for Your suggestion about update VS, this solved problem with starting application at WP10.

    Now I see, that my problem is only at phone with WP8.1, at phone with WP10 it work great!

    I have additional question if I may. There is any possible to capture moment after sharing, it mean for example terminate application after sharing or navigate to last view? Because now, after sharing application automatically restart.

    • Edited by Nevendar Wednesday, December 2, 2015 12:39 PM
    Wednesday, December 2, 2015 12:39 PM
  • can you share a project that shows that it crash? then can dig in it but with the sample code it works for me

    Microsoft Certified Solutions Developer - Windows Store Apps Using C#

    Wednesday, December 2, 2015 3:53 PM
  • Problem solved. One line of code was sufficient.

    After take a photo, and save on the phone, we should dispose MediaCapture object.

    Apparently Windows Phone 10 do it automatically in contrast to WP8.1, so application work correct (or better memory management).

    Thank You for all suggestions.

    Wednesday, December 9, 2015 9:34 AM