Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Looking for an explanation of the 'Asynchronous' word in .Net?

I need someone to explain the following names;

  1. Asynchronous Delegates.
  2. Asynchronous methods.
  3. Asynchronous events.

I'm currently going over this for my 70-536 exam and I am covering all my bases so far. The threading chapter and online resources have been good to me on my second read through. Still though, the names used above mean absolutely nothing to me? I would really appreciate the meaning behind the word 'Asynchronous' and its relevance to Delegates, methods and events.

Feel free to go into as much detail as you like.

like image 655
IbrarMumtaz Avatar asked Nov 29 '22 06:11

IbrarMumtaz


2 Answers

'Asynchronous' describes a type of execution flow.

Synchronous instructions execute linearly and prevent subsequent instructions from executing until complete (that is, they block). So given the following synchronous code:

DoOneThing();
DoAnotherThing();

DoAnotherThing doesn't execute until DoOneThing is finished.

Asynchronous instructions differ in that you don't know (or sometimes even care) when they start or finish executing. In a case like this:

DoOneAsynchronousThing();
DoAnotherThing();

The first statement initiates the asynchronous operation, then does another thing immediately before the first operation is completed (or perhaps even started).

There are many different mechanisms for providing asynchronous execution: the most common ones (at least in the .NET world) are probably the ThreadPool (for in-process asynchronous execution) and Microsoft Message Queue (for inter-process asynchronous execution). For a .NET-specific introduction, you might start with this MSDN topic, "Including Asynchronous Calls".

So asynchronous delegates, methods, and events all run (and complete) at indeterminate times and do not block the main thread of execution.

like image 71
Jeff Sternal Avatar answered Dec 05 '22 02:12

Jeff Sternal


I am a believer in studying and finding your answers when it comes to an exam.

Here are some articles

Read the wiki on it: http://en.wikipedia.org/wiki/Asynchronous_communication

Or here on "What is async", this one is short and to the point: http://www.webopedia.com/TERM/A/asynchronous.html

On example is say in my code, i have a serial port. One thread reads and one thread writes to the port. I can read and write at the same time (sort of) so this is ASYNC. If i were blocking the incomming data while i am writting then i would be synchronous.

like image 21
Roast Avatar answered Dec 05 '22 01:12

Roast