0

I'm new to asynchronous programming in c#.

So here is my code:

    private async Task testDeleteBank(int id)
    {
        await _msBankRepo.DeleteAsync(id);
        var checkBank = (from A in _msBankRepo.GetAll()
                         where A.Id == id
                         select A).Count();
        if(checkBank > 0)
        {
            Console.Write(checkBank);
        }
    }

    public void testAsync(GetAllBankListDto input)
    {
        testDeleteBank(input.bankID);
        UpdateMsBank(input);
    }

When I run testAsync method, it does update a record in my table. But why it's not deleting my record after DeleteAsync method?

hadie
  • 31
  • 2

1 Answers1

0

You should await testDeleteBank(input.bankID) in:

public async Task testAsync(GetAllBankListDto input)
{
    await testDeleteBank(input.bankID);
    // UpdateMsBank(input);
}

If you need test to be synchronous, use AsyncHelper in:

public void test(GetAllBankListDto input)
{
    AsyncHelper.RunSync(() => testDeleteBank(input.bankID));
    // UpdateMsBank(input);
}
aaron
  • 39,695
  • 6
  • 46
  • 102