user7560542
user7560542

Reputation: 547

Is there any difference between "await SaveChangesAsync()" and "SaveChanges()"? They seem to do the same thing

My understanding is that

await myContext.SaveChangesAsync();

will save the changes, but not allow the thread to continue in the same manner that

myContext.SaveChanges();

behaves.

Is there any difference between these two?

Upvotes: 1

Views: 1439

Answers (1)

Stephen Cleary
Stephen Cleary

Reputation: 457157

allow the thread to continue

This is your misunderstanding.

Put simply, synchronous methods like SaveChanges block the calling thread until the method completes.

Asynchronous methods like SaveChangesAsync (when consumed with await) will not block the calling thread. The await will "pause" the method, but it will not block the thread.

You can find more information about how this works in my async intro blog post and my post on There Is No Thread.

Upvotes: 3

Related Questions