locked
Can I used code to control FileOpenPickerUI cancel button state? RRS feed

  • Question

  • Hi,

    I used the FileOpenPickerUI in my apps, can I used code to control the cancel button?

    just like disable or enable?


    自强不息,知行合一。

    Sunday, September 22, 2013 2:36 AM

Answers

  • I can reproduce this issue, and it is a bug, so I will file it.  It also reproduces in 8.1.  However, I am not sure if this scenario is something that you're going to encounter.  If you use a single app to both pick the file and host the file picker contract, then the single app will crash because by the time that the thread is finishing up it's work (the delay), the window isn't there any more and it send out that exception in the same process.  However, if you have two separate processes working together (a file picker and a file picker contract process, delivering a file), the contact process is the one that crashes.  I don't know of any way to capture the exception in either case, since the exception is more in the fact that the OS is completing a task and delivering the output to a thread which is in the process of shutting down or has already shut down.  There's no exception in the button-click code.


    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Wednesday, October 2, 2013 4:17 PM
    Moderator

All replies

  • No. The app cannot affect the running picker UI once launched.

    --Rob

    Sunday, September 22, 2013 2:41 PM
    Moderator
  • Hi, Rob

    Thank you for your answer.

    I used the picker UI, the content in my app is encode asynchronously, when the async is not completed,

    the user close the picker UI, and then exception happend, like this "the operation can't complete becase the window is closed".

    thank you!


    自强不息,知行合一。

    Monday, September 23, 2013 1:17 AM
  • This exception how to solve it?

    thank you!


    自强不息,知行合一。

    Tuesday, September 24, 2013 3:23 AM
  • I try to use try catch, but it doesn't catch the exception!

    自强不息,知行合一。

    Tuesday, September 24, 2013 11:51 AM
  • Catch the exception, then throw it on the UI thread using a Dispatcher.

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Wednesday, September 25, 2013 3:07 PM
    Moderator
  • Hi Matt Small,

    I just want to catch the exception, but I don't know how to do it.

    My code is:

    public IAsyncAction SaveToFileAsync(IStorageFile file) { Task task = Task.Run( async () => { string strXml = "****"; XmlDocument docTotal = new XmlDocument(); docTotal.LoadXml(strXml ); await docTotal.SaveToFileAsync(file); }); return task.AsAsyncAction(); } //In FileOpenPickerUI I do this

    //Omits the part of the code

    public async void SaveToFile(IStorageFile file) { try { await SaveToFileAsync(file); } catch (System.Exception ex) { //do something } }

    in the catch, I can't catch this exception. the exception is 0x802a0201.

    I guess at this point, the fileOpenPickerUI has been closed, it is impossible to catch this exception. Right?

    how to solve it? Thank you!


    自强不息,知行合一。

    Thursday, September 26, 2013 1:25 AM
  • Hi Matt Small,

    I used the sample "File picker contracts sample (Windows 8)\C#", I change the code in FileOpenPicker_PickAppFile.xaml.cs like follow:

    private async void AddLocalFileButton_Click(object sender, RoutedEventArgs e)
            {
                try
                {
                    await System.Threading.Tasks.Task.Delay(5000);
                }
                catch (System.Exception ex)
                {
                	
                }
            }

    if I close the PikerUI in 5000ms, the exception(0x802a0201) is happened. And the catch can't catch this exception.

    How to fix it? Thank you!


    自强不息,知行合一。

    Thursday, September 26, 2013 2:20 AM
  • :

    public IAsyncAction SaveToFileAsync(IStorageFile file) { Task task = Task.Run( async () => { string strXml = "****"; XmlDocument docTotal = new XmlDocument(); docTotal.LoadXml(strXml ); await docTotal.SaveToFileAsync(file); }); return task.AsAsyncAction(); } //In FileOpenPickerUI I do this

    //Omits the part of the code

    public async void SaveToFile(IStorageFile file) { try { await SaveToFileAsync(file); } catch (System.Exception ex) { //do something } }


    Is it just me or is this an infinite loop?
    SaveToFileAsync calls SaveToFile which calls SaveToFileAsync...

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Friday, September 27, 2013 3:12 PM
    Moderator
  • hi Matt Small,

    it's not  an infinite loop. SaveToFile calls SaveToFileAsync, and then calls XmlDocument's  SaveToFileAsync.

    so it's not an infinite loop.

    And the sample "File picker contracts sample (Windows 8)\C#", it just throw this excetption.

    I change the code in FileOpenPicker_PickAppFile.xaml.cs like follow:
    private async void AddLocalFileButton_Click(object sender, RoutedEventArgs e)
            {
                try
                {
                    await System.Threading.Tasks.Task.Delay(5000);
                }
                catch (System.Exception ex)
                {
                	
                }
            }

    if I close the PikerUI in 5000ms, the exception(0x802a0201) is happened.

    how to fix it? Thank you!


    自强不息,知行合一。

    Sunday, September 29, 2013 1:23 AM
  • I can reproduce this issue, and it is a bug, so I will file it.  It also reproduces in 8.1.  However, I am not sure if this scenario is something that you're going to encounter.  If you use a single app to both pick the file and host the file picker contract, then the single app will crash because by the time that the thread is finishing up it's work (the delay), the window isn't there any more and it send out that exception in the same process.  However, if you have two separate processes working together (a file picker and a file picker contract process, delivering a file), the contact process is the one that crashes.  I don't know of any way to capture the exception in either case, since the exception is more in the fact that the OS is completing a task and delivering the output to a thread which is in the process of shutting down or has already shut down.  There's no exception in the button-click code.


    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Wednesday, October 2, 2013 4:17 PM
    Moderator
  • Hi Matt Small,

    Thank you for your help.

    I just have another question.

    when I used the sample "File picker contracts sample (Windows 8)\C#"

    I used the pick file function , I selected the File picker contracts sample self,

    It have a PickerHost.exe, when I close the picker UI, the PickerHost.exe is not exit.

    If I do this 3 times, it have three PickerHost.exe, like the follow image. why?


    自强不息,知行合一。

    Tuesday, October 8, 2013 6:54 AM
  • Well, it's apparent that it spins up a new instance for every time you use it.  Have you waited to see if it goes away on its own?


    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Tuesday, October 8, 2013 1:17 PM
    Moderator
  • Hi, Matt Small

    If you do not close the FilePickerContracts.exe itself,the PickerHost.exe does not goes away on its own.

    Thank you!


    自强不息,知行合一。

    Thursday, October 10, 2013 6:50 AM