5

Can any one tell me difference between GetAwaiter() and ConfigureAwait(false).

Both of them are used in Async method to solve the deadlock situation and ConfigureAwait to complete task without using Synchrnoization context. I'm looking for scenarios where we can use GetAwaiter() and where we use ConfigureAwait(false).

I heard if it is library I'm building then I need to use ConfigureAwait(false) which generates Configurable Awaitable object of Await task. Can I use ConfigureAwait in Unittest case project or should use GetAwaiter() which get await task.

Nipuna
  • 6,846
  • 9
  • 64
  • 87
user145610
  • 2,949
  • 4
  • 43
  • 75
  • 6
    Your question is at the same time far too broad and not clear at all. The two methods do completely different things; what "difference" other than that do you think is worth asking about? Neither are used _"to solve the deadlock situation"_; it's true that correct use of either can _avoid_ deadlock, but it's not like you start with some random deadlock, throw in a call to one of those methods and, Bob's your uncle, deadlock is solved. – Peter Duniho Nov 20 '15 at 20:45

2 Answers2

3

Extracted from MSDN Docs

Task.GetAwaiter Gets an awaiter used to await this task. See more details here and here.

Task.ConfigureAwaiter Configures an awaiter used to await this task. See more details here and here

Community
  • 1
  • 1
Nipuna
  • 6,846
  • 9
  • 64
  • 87
2

Here is some guidance:

Async/Await - Best Practices in Asynchronous Programming

and another similar question:

Preventing a deadlock when calling an async method without using await

You can use Rx to mimic async operations in unit tests. I would advise against having actual async in unit tests; it would slow them down and discourage using those unit tests.

Community
  • 1
  • 1
toddmo
  • 20,682
  • 14
  • 97
  • 107