Q:

Why do tasks returned from JSRuntime.InvokeAsync during OnInitAsync never finish in Blazor?

0

This code will help you to understand how to InvokeAsync during OnInitAsync never finish in Blazor and why do tasks returned from JSRuntime.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

This is a known bug and is resolved in the upcoming release of Blazor Preview 3. [Issue Resolved]

[wwwroot/index.html]

<script>
        window.interopDuringOnInit = function () {
            return "Hello World";
        }
</script>

[Razor]

@code {
    string Greeting;

    protected override async Task OnInitializedAsync()
    {
        try
        {            
            Greeting = await JSRuntime.InvokeAsync<string>("interopDuringOnInit");
        }
        catch (Exception ex)
        {
            Console.WriteLine("Could not invoke interop during OnInit, " + ex.ToString());
        }
    }
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now