-2

When I change the method signature to be Task Entity Framework hangs at SaveChanges. Why would this be happening?

This code fails

public async Task<bool> SaveAsync(agency agency)
    {
        using (var ctx = new AvnEntities())
        {
            try
            {
                ctx.agencies.Add(agency);
                await ctx.SaveChangesAsync();
                return true;
            }
            catch (System.Exception)
            {
                return false;
            }
        }
    }

This code works

public async Task SaveAsync(agency agency)
    {
        using (var ctx = new AvnEntities())
        {
            try
            {
                ctx.agencies.Add(agency);
                await ctx.SaveChangesAsync();
            }
            catch (System.Exception)
            {
                throw;
            }
        }
    }
Brian Emmerling
  • 37
  • 1
  • 2
  • 8
  • I'm betting it relates to this... https://stackoverflow.com/questions/14526377/why-does-this-async-action-hang You need to post the code calling this method which is hanging. – Mick Jun 01 '18 at 00:56

1 Answers1

-1

As comment by Mick and this post here Asyn-Hanging

I created a deadlock because in my UI thread I was waiting to get Task.Result.

Brian Emmerling
  • 37
  • 1
  • 2
  • 8