-3

C# is a synchronous language, i.e process will block UI until result comes, now trouble is; this async with await looks like same thing as synchronous.

async + await = synch

I do understand the caller moves on, i.e the main thread is released.

Code Guru
  • 21
  • 1
  • 8
    So what is your question? – dotnetom Oct 10 '15 at 19:33
  • Please learn the basics of async and await these are is NOT synchronous Check out: https://msdn.microsoft.com/en-us/library/hh191443.aspx?f=255&MSPPError=-2147217396 – Jim Oct 10 '15 at 19:40
  • http://stephenhaunts.com/2014/10/16/using-async-and-await-to-update-the-ui-thread-part-2/ – Eric J. Oct 10 '15 at 19:40
  • You're right in that it releases the thread, but that doesn't mean it's the same as synchronous. The awaited task will be executed later on. If it were synchronous, it would stop until the task was executed. –  Oct 10 '15 at 19:42
  • So releasing the main thread is what we get, the called method still awaits sound a little synchronous to me that ways – Code Guru Oct 10 '15 at 19:46
  • Ah, I get it; it means we will only mark those methods as async which do not return a result we depend on and hence we will move on with main thread and new thread will wait. – Code Guru Oct 10 '15 at 19:50
  • 1
    No sir, you can mark methods that return a result also as Task, please read trough the required documentation that is posted to understand the mechanism and usage of async and await. – Jim Oct 10 '15 at 19:53
  • Your comparing a single task, you can await multiple tasks and they will execute asynchronously from each other. – Eric Kelly Oct 10 '15 at 20:06

2 Answers2

1

You can avoid performance bottlenecks and enhance the overall responsiveness of your application by using asynchronous programming.

However, traditional techniques for writing asynchronous applications can be complicated, making them difficult to write, debug, and maintain.

Visual Studio 2012 introduces a simplified approach, async programming, that leverages asynchronous support in the .NET Framework 4.5 and the Windows Runtime.

The compiler does the difficult work that the developer used to do, and your application retains a logical structure that resembles synchronous code. As a result, you get all the advantages of asynchronous programming with a fraction of the effort.

MSDN documentation here

Jim
  • 2,974
  • 2
  • 19
  • 29
0

C# is a synchronous language, i.e process will block UI until result comes

1) C# has nothing to do with the UI. The UI is implemented as a framework, and language agnostic.

2) Just counting the desktop, there is at least 2 UI framework, there is no "UI"

3) You are right, the 2 out of the box frameworks has thread affinity, and there is one main message pump. (btw nothing prevents you to do as many as you want, just your controls created in each must be accessed on that one exclusively, called "serialization" and it is a well known multiprogramming design pattern.

Now back to the main topic in the title.

Obviously you understand how async / await work. What is your misunderstanding what we can mean on asynchronous.

Please note: when you use async/await, it does not block the thread. After the async-ed execution completed that is the continuation in the code flow. If it would be implemented as a completion handler, or a callback, everyone would see what is it. Now it is written as the next lines of the code. I admit it can mislead one, but is is more convenient than writing (inline) completion handlers, especially if you have say 5 async operations in a row, then you must nest the completions in 4 levels. That is what C# compiler generates for you using async/await, and let you to write the code in a line by line matter.

Anyway, as you wrote

I do understand the caller moves on, i.e the main thread is released.

so it's async.

g.pickardou
  • 32,346
  • 36
  • 123
  • 268