locked
Background task causes OpenStreamForReadAsync() to be blocked

    Question

  • It is weird that OpenStreamForReadAsync() is blocked for a long time. I know I can use await to keep UI responsive, but OpenStreamForReadAsync() never come back with result when I have some background task. Here is the code.

    Background task:

    publicsealedclass MyBackgroundTask: IBackgroundTask{

         public voidRun(IBackgroundTaskInstancetaskInstance){

              BackgroundTaskDeferral deferral = taskInstance.GetDeferral();

               // do background work

          deferral.Complete();

    }

    register background:

    public staticasyncTask<BackgroundTaskRegistration> registerBackGroundTask(){

    vartaskRegistered = false;

    varexampleTaskName = "MyBackgroundTask";

    awaitBackgroundExecutionManager.RequestAccessAsync();//check if there is already registered. Otherwise, register it.

    varbuilder = newBackgroundTaskBuilder();

    builder.Name = exampleTaskName;

     builder.TaskEntryPoint = "MyBackgroundTask";

    builder.SetTrigger(trigger);

    BackgroundTaskRegistrationtask = builder.Register();

    returntask;

    }

    Then when I call OpenStreamForReadAsync, it won't never return.

    using (varst = awaitWindows.Storage.ApplicationData.Current.LocalFolder.OpenStreamForReadAsync(fileName)){}

     If I disable the background task and uninstall/reinstall, then OpenStreamForReadAsync() works fine.

    Why should OpenStreamForReadAsyncb be blocked by the background task? The background task doesn't have any access to the file to be opened by OpenStreamForReadAsync().



    Great Wall

    Thursday, September 11, 2014 7:46 AM

All replies

  • Please provide a working project for this issue, and I'll check it out.

    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.

    Thursday, September 11, 2014 7:44 PM
    Moderator