locked
How to used the PickerClosingOperation.GetDeferral | getDeferral method RRS feed

  • Question

  • Hi,

    How to used the PickerClosingOperation.GetDeferral | getDeferral method?

    In my app, I called follow codes,

    async void  fileOpenPickerUI_Closing(Windows.Storage.Pickers.Provider.FileOpenPickerUI sender, Windows.Storage.Pickers.Provider.PickerClosingEventArgs args)
            {
                var defer = args.ClosingOperation.GetDeferral();
                storage file =  await SaveToFileAsync("aaaa", filePath);
    defer.Complete();
            }

    but it doesnot work well, it's not async? how can I do it?

    Thank you!


    自强不息,知行合一。

    Sunday, September 22, 2013 9:26 AM

All replies

  • Can you please explain what's not working properly?

    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.

    Monday, September 23, 2013 12:12 PM
    Moderator
  • Thank you for your reply!

    In my app, when the pickerUI closed, I want to save a xml file, just like this: A app call my app's FileOpenPicker,

    (my App is a photo app) then user select a photo,  I want to add a xml file also. so user select a photo, there will two files in the pikerUI.

    and the xml file I want save it in the Closing event, but it doesnot work well.

    the problem is the xml is not save complete, A app just get it. Then it can't work.

    any idea to do it? Thank you!


    自强不息,知行合一。

    Tuesday, September 24, 2013 2:35 AM
  • Some ideas?

    自强不息,知行合一。

    Sunday, September 29, 2013 8:42 AM
  • Hi Matt Small,

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

    protected override void OnNavigatedTo(NavigationEventArgs e)
            {
                UpdateButtonState(fileOpenPickerUI.ContainsFile(id));
                fileOpenPickerUI.FileRemoved += new TypedEventHandler<FileOpenPickerUI, FileRemovedEventArgs>(OnFileRemoved);
                fileOpenPickerUI.Closing += fileOpenPickerUI_Closing;
            }
    
            async void fileOpenPickerUI_Closing(FileOpenPickerUI sender, PickerClosingEventArgs args)
            {
                System.Diagnostics.Debug.WriteLine("fileOpenPickerUI_Closing 0");
                var defer = args.ClosingOperation.GetDeferral();
    
                StorageFile file = await ApplicationData.Current.LocalFolder.CreateFileAsync("test.txt", CreationCollisionOption.GenerateUniqueName);
    
                Windows.Storage.Streams.IRandomAccessStream stream = await file.OpenAsync(FileAccessMode.ReadWrite);
    
                System.Diagnostics.Debug.WriteLine("fileOpenPickerUI_Closing 1");
                defer.Complete();
                System.Diagnostics.Debug.WriteLine("fileOpenPickerUI_Closing 2");
            }

    I change the MainPage_PickFile.xaml.cs like follow:

    private async void PickFileButton_Click(object sender, RoutedEventArgs e) { MainPage page = MainPage.Current; page.ResetScenarioOutput(OutputTextBlock); if (page.EnsureUnsnapped()) { // Set up and launch the Open Picker FileOpenPicker fileOpenPicker = new FileOpenPicker(); fileOpenPicker.ViewMode = PickerViewMode.Thumbnail; fileOpenPicker.FileTypeFilter.Add(".png"); IReadOnlyList<StorageFile> files = await fileOpenPicker.PickMultipleFilesAsync(); //I add this line

    System.Diagnostics.Debug.WriteLine("get files"); StringBuilder fileNames = new StringBuilder(); foreach (StorageFile file in files) { // At this point, the app can begin reading from the provided file fileNames.AppendLine(file.Name); } OutputTextBlock.Text = fileNames.ToString(); } }

    when debug this code, in output window you can see the write line is:

    get files
    fileOpenPickerUI_Closing 0
    fileOpenPickerUI_Closing 1
    fileOpenPickerUI_Closing 2

    I want to it like this:

    fileOpenPickerUI_Closing 0
    fileOpenPickerUI_Closing 1
    fileOpenPickerUI_Closing 2

    get files

    so I said the defer is not work well. Some ideas? Thank you!


    自强不息,知行合一。

    Tuesday, October 8, 2013 6:39 AM
  • How about this? Thank you!


    自强不息,知行合一。

    Wednesday, October 9, 2013 3:23 AM
  • Any suggestion?

    自强不息,知行合一。

    Tuesday, October 15, 2013 6:04 AM