Skip to content

Relaunching an app before OnInitializeAsync is completed causes NullReferenceException #1206

Closed
@pekspro

Description

Add this in the blank project app.xaml.cs-file in the current source:

public override async Task OnInitializeAsync(IActivatedEventArgs args)
{
    System.Diagnostics.Debug.WriteLine("*** Starts OnInitializeAsync...");

    await Task.Delay(30 * 1000);

    System.Diagnostics.Debug.WriteLine("*** OnInitializeAsync is completed.");

    await base.OnInitializeAsync(args);
}

Now launch the application from Visual Studio. Then before the 30 seconds timeout is completed launch the application again via the start menu. This will create a NullReferenceException.

This is because then the application is relaunched InternalLaunchAsync is called which calls CallOnStartAsync which then calls OnStartAsync which wants to use NavigationService that is null in that moment.

Yes, this is a really evil case :-). But this has caused me problems when running my app on the phone, which takes about 2 seconds two start. I have noticed that sometime I launch my app by mistake and goes back two start screen before it’s booted. And then when I launch it later it’s crashes.

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions