(awaitable) task, not all code paths return a value

Ok My employee object has a list of EmployeePayHistories which are displayed in a datagrid. I have a method to get the selected row from the datagrid and here I am trying to actually implement the function. However on the DeleteEmployeePayHistories() part its giving me an error saying its awaitable. I would love to know how to fix it, and why its doing it. Thanks in advance for any help.

    private Task DeleteEmployeePayHistories()
        {
           Employee.EmployeePayHistories.Remove(SelectedPayHistory);
           SelectedPayHistory = null;
        }

2 answers

  • answered 2018-07-12 07:18 Selman Genç

    Your method returns a Task, if you don't want it to be awaitable and return nothing, change return type to void.

    private void DeleteEmployeePayHistories()
    

  • answered 2018-07-12 07:18 Jamiec

    Your method should either return a Task (probably Task.CompletedTask) or use the async keyword and await something.

    private Task DeleteEmployeePayHistories()
    {
        Employee.EmployeePayHistories.Remove(SelectedPayHistory);
        SelectedPayHistory = null;
        return Task.CompletedTask;
    }
    

    or

    private async Task DeleteEmployeePayHistories()
    {
        // something in here should use await or you'll get another warning
        Employee.EmployeePayHistories.Remove(SelectedPayHistory);
        SelectedPayHistory = null;
    }
    

    Finally, if you have no need for async code, you could just make your method void

    private void DeleteEmployeePayHistories()
    {
        Employee.EmployeePayHistories.Remove(SelectedPayHistory);
        SelectedPayHistory = null;
    }