简体   繁体   中英

Launch all the await task at the same time in Xamarin forms

I am learning xamarin Async,

I have a function that translate many sentences asynchronously.

I would like to change my function in order to launch all the await at the same time in App.xml.cs because some translations are not finished and I am redirected in MainPage

Here my fuction with all the await:

public async Task SetLeafLanguage() 
{
        var phoneLanguage = "fr";// CultureInfo.CurrentUICulture.TwoLetterISOLanguageName;

        // transversal
        var WarningConnexionText = await MicosoftTranslater.TranslateText("this the first text", phoneLanguage);

        // Test page 
        var NumberOfWords = await MicosoftTranslater.TranslateText("this the second text", phoneLanguage);


        var ExerciceTitle = await MicosoftTranslater.TranslateText("this the second text", phoneLanguage);

        var AnswerPlaceHolder = await MicosoftTranslater.TranslateText("this the second text", phoneLanguage);

        var LabelNumberOfWordToTranslate = await MicosoftTranslater.TranslateText("this the second text", phoneLanguage);

        // parameter labels
        var AboutUstext = await MicosoftTranslater.TranslateText("this the second text", phoneLanguage);

}


public async Task GetUserOnData()
{
    await SetLeafLanguage();
    MainPage = new MainPage();
}

public App ()
{
    InitializeComponent();
    GetUserOnData();
}

Simple. DO NOT AWAIT.

Colellect the threads, and then possibly await them once all the services have started. NOTHING forces you to await the task returned right in the same line.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM