Skip to content

Instantly share code, notes, and snippets.

@SangSuantak
Last active October 7, 2023 04:11
Show Gist options
  • Save SangSuantak/e581e77e525ff8e501e74192cd3909cf to your computer and use it in GitHub Desktop.
Save SangSuantak/e581e77e525ff8e501e74192cd3909cf to your computer and use it in GitHub Desktop.
C# Async & Await Key Points
  1. Introduced in .Net 4.5
  2. The method signature includes an async modifier.
  3. The name of an async method, by convention, ends with an Async suffix.
  4. The return type is one of the following types:
    • Task<TResult> if your method has a return statement in which the operand has type TResult.
    • Task if your method has no return statement or has a return statement with no operand.
    • void if you're writing an async event handler. This return type is used primarily to define event handlers, where a void return type is required.
  5. The method usually includes at least one await expression, which marks a point where the method can't continue until the awaited asynchronous operation is complete. In the meantime, the method is suspended, and control returns to the method's caller.
  6. When the async method eventually completes its work, the task is marked as completed and the result, if any, is stored in the task.
  7. The async and await keywords don't cause additional threads to be created. Async methods don't require multithreading because an async method doesn't run on its own thread. The method runs on the current synchronization context and uses time on the thread only when the method is active.
  8. The marked async method can use await to designate suspension points. The await operator tells the compiler that the async method can't continue past that point until the awaited asynchronous process is complete. In the meantime, control returns to the caller of the async method.
  9. The suspension of an async method at an await expression doesn't constitute an exit from the method, and finally blocks don’t run.
  10. An async method typically contains one or more occurrences of an await operator, but the absence of await expressions doesn’t cause a compiler error. If an async method doesn’t use an await operator to mark a suspension point, the method executes as a synchronous method does, despite the async modifier. The compiler issues a warning for such methods.
  11. An async method that has a void return type can’t be awaited, and the caller of a void-returning method can't catch any exceptions that the method throws.
  12. An async method can't declare ref or out parameters, but the method can call methods that have such parameters.

Source: https://msdn.microsoft.com/en-us/library/mt674882.aspx

@Offe1981
Copy link

Offe1981 commented Oct 7, 2023

Hello everyone, you'll be pleased to know that I stumbled on a page today that explains why lawyers are being barred from attorney suspended from practice I have received entire information about it. And now I'd like to share that information with all of you. I hope you enjoyed reading this information

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment