4

I am working on Dotnet Core Blazor and getting below error while using EventCallBack to bind the parent grid after delete events. Below the code for using Child component

<tbody>
      @foreach (var employee in Employees)
       {
          <BlazorAppDemo.Pages.Controls.EmployeeList Employee="employee"
                                                           ShowFooter="ShowFooter"
                                                           OnEmployeeSelectionChange="onEmployeeSelectionChanged"
                                                           btnDeleteClick="OnEmployeeDeleted" >

            </BlazorAppDemo.Pages.Controls.EmployeeList>
        }
    </tbody> 

EmployeeList child component is below

<tr>
@*<td>@Employee.EmployeeId</td>*@
<td><input type="checkbox" @onchange="CheckBoxChanged" /></td>
<td>@Employee.Department.DepartmentName</td>
<td>@Employee.FirstName</td>  
<td>@Employee.DateOfBirth.ToShortDateString()</td>
<td><img class="card-img-top img-thumb" style="width:50px;height:50px" src="@Employee.PhotoPath" /></td>
@if (ShowFooter)
{
    <AuthorizeView Roles="Admin" Policy="OldEmployeeBefore2020">
        <Authorized>
            <td>
                <a href="@($"employeedetails/{Employee.EmployeeId}")" class="btn btn-primary m-1">View</a>
                <a href="@($"employeeEdit/{Employee.EmployeeId}")" class="btn btn-primary m-1">Edit</a>
                @*<a href="#" class="btn btn-danger m-1">Delete</a>*@
                <button class="btn btn-danger m-1" @onclick="btnDelete_Click">
                </button>
            </td>
        </Authorized>
    </AuthorizeView> 
}

Delete Button Event :

 [Parameter]
    public EventCallback<int> btnDeleteClick { get; set; }

 protected async Task btnDelete_Click()
    {
        var response = await EmployeeService.Delete(Employee.EmployeeId).ConfigureAwait(false);

        if (string.IsNullOrEmpty(response.ErrorMessage))
        {               
            await btnDeleteClick.InvokeAsync(Employee.EmployeeId);               
            //NavigationManager.NavigateTo("employee");
        }
    }

Parent page has subscribed the delete event:

 protected async Task OnEmployeeDeleted(int id)
    {
        var response = await EmployeeService.GetEmployees().ConfigureAwait(false);
        if (response.Result != null)
        {  
            Employees = response.Result.Result; 
        }
        else
        {
            PageMessage = response.ErrorMessage;
        }
    }

1 Answer 1

2

You should remove the .ConfigureAwait(false) (2x as far as I coud see).

When you use async/await correctly in Blazor you should almost never need it.

When you do use it you are asking for the remainder of the event to be run on a different thread. The wrong thread in most cases.

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks for reply. After removed the .ConfigureAwait(false) it started working now. I configured because i was getting warning everywhere in async call "Consider Calling ConfiguredAwait on the awaited Task".
Can you post the text or number of that warning? Because that shouldn't happen.
Can you post a minimal repo demonstrating your problem? I'd like to experiment so I can see if this is a bug.
Wait, i am trying to upload my repo on git. Once it done will let you know.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.