[Solved] Awaited method call doesnt appear to complete [closed]


The problem is you have two separate tasks running that call ShowProgressText. Task.Run() is not something you normally use unless you are interfacing with code that does not use the C# async/await pattern. So perhaps LoadRapport could be like this:

    bool IsCompleted;
    string LogText;

    private async Task LoadRapport()
    {
        LogText = "Disable Replication";
        IsCompleted = false;

        _ = ShowStatus(); // start this task but don't wait for it to finish.

        // Start these long running methods on a separate non UI thread using Task.Run.
        await Task.Run(() => DisableReplication());

        LogText = "Importing Weights";

        await Task.Run(() => ImportWeights());

        IsCompleted = true; // tell ShowStatus to complete.
    }

and ShowStatus could be like this:

    async Task ShowStatus()
    {
        while (!IsCompleted) {
            BeginInvoke(new Action(() =>
            {
                UpdateProgressText(this.LogText);
            })); ;
            await Task.Delay(200);
        }

        UpdateProgressText("Completed");
    }

I would also remember to disable the button that calls BtnGetRapportFile during this long running process so the user doesn’t click it 10 times and get 10 separate threads running calling your SQL server…

1

solved Awaited method call doesnt appear to complete [closed]