Skip to content

Race condition issue when subscribing to ProviderStateChanged #124

@pekspro

Description

@pekspro

Describe the bug

There is a race condition issue when subscribing to ProviderManager.Instance.ProviderStateChanged. Currently this only works if you do this before ProviderManager.Instance.GlobalProvider is setup.

Steps to Reproduce

It is easy to see this in the UwpMsalProviderSample project. Change the constructor of LoginButton to this:

    public LoginButton()
    {
        InitializeComponent();

        _ = Task.Run(async () =>
        {
            await Task.Delay(2000);

            _ = Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
           {
               ProviderManager.Instance.ProviderStateChanged += (s, e) => UpdateState();
               UpdateState();
           });
        });
    }

Now when the application is executed the text on the sign in button will not be updated.

Expected behavior

It should not matter when you subscribe to ProviderManager.Instance.ProviderStateChanged.

Additional context

I will create an PR for this.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions