How to perform a delay in the App constrictor?

JassimRahmaJassimRahma USMember ✭✭✭✭

Hi,

I am using OneSignal in my app and I am initializing it in the App.Xaml.cs like this:

public App()
{
    InitializeComponent();

    OneSignal.Current.StartInit("xxxxxx-xxx-xxx-xxxxx-xxxxxxxxxxx")
        .Settings(new Dictionary<string, bool>() {
        { IOSSettings.kOSSettingsKeyAutoPrompt, false } })
            .EndInit();
}

After the OneSignal.Current.StartInit I want to make a delay for few seconds and then I want to run:

OneSignal.Current.IdsAvailable((playerID, pushToken) =>
{
    id = playerID;
    App.Current.MainPage.DisplayAlert("playerId", id.ToString(), "OK");
});

because it's faking to get the IdsAvailable that quick.

How can I do that please?

Thanks,
Jassim

Tagged:

Best Answer

Answers

  • N_BauaN_Baua INMember ✭✭✭✭✭

    Hi @JassimRahma,

    There are two ways to do it,
    asynchronously: await Task.Delay(2000); //wait for two seconds
    OR
    synchronously: Task.Delay(2000).Wait(); //wait for two seconds

    Make sure you're not blocking the UI thread while waiting and/or your operation is too frequent.

    Hope it helps.

    -- N Baua

  • JassimRahmaJassimRahma USMember ✭✭✭✭

    but that is not accepted in the App constructor

Sign In or Register to comment.