c#-5.0

How does C# 5 async return to main thread?

亡梦爱人 提交于 2019-12-21 05:37:18
问题 I was watching a vid about Async CTP and saw that if you call await from e.g. main thread , then the execution will continue from main thread when the work is completed. e.g //called from main thread var result = await SomeAsyncWork(); //this will execute in main thread also console.writeline(result) I had the naive impression that there would be a normal call back going on which would be executed on a worker thread. At some level that must be what is going on since you can wrap normal async

Async Await targeting 4.0 deployment requirements

耗尽温柔 提交于 2019-12-21 05:26:08
问题 Microsoft has updated the async/await targeting for .net 4.0 and now suggests using the Microsoft.Bcl.Async library available on nuget. In the release notes, it states that .net 4 with KB 2468871 is required. Is KB2468871 a build requirement or a deployment requirement? What aspect of KB2468871 makes it required? 回答1: Quoting from http://support.microsoft.com/kb/2468871/en-us Feature 5 Changes to the support portable libraries. These changes include API updates and binder modifications. This

The awaitable and awaiter In C# 5.0 Asynchronous

爱⌒轻易说出口 提交于 2019-12-21 04:02:35
问题 Task or Task<TResult> object is awaitable, so we can use await key on those whose return value is Task or Task<TResult>. Task or Task<TResult> are the most frequently-used awaitable object. We also can define our own awaitable object.The object should has below qualification. It has a GetAwaiter() method (instance method or extension method); Its GetAwaiter() method returns an awaiter. An object is an awaiter if: It implements INotifyCompletion or ICriticalNotifyCompletion interface; It has

C# 5 async/await thread mechanics feel wrong?

不羁的心 提交于 2019-12-20 12:27:56
问题 Why have the calling thread walk into the async method until the inner 'await'? Isn't it cleaner to just spawn a thread as soon as an async method is called. That way you know for sure that the async method returns immediately. You don't have to worry about not doing anything expensive at the early stages of the async method. I tend to like to know whether a method is going to execute code on 'my' thread or not. Whether it's blocking or not. This model seems to open a whole spectrum of in

await/async vs. “classic” asynchronous (callbacks)

被刻印的时光 ゝ 提交于 2019-12-20 09:06:23
问题 So the new async CTP is very cool; it makes my life a lot easier not having to write named callback methods and makes the intent of the methods a lot clearer. Now that I've gotten to play with it a little, I'm wondering what differences there may be between the async/await and the "classic" asynchronous callback syntaxes. Here are a few questions I have in mind, but there are numerous others that I won't have thought of now and probably will later. Does one perhaps offer superior performance

await/async vs. “classic” asynchronous (callbacks)

試著忘記壹切 提交于 2019-12-20 09:05:41
问题 So the new async CTP is very cool; it makes my life a lot easier not having to write named callback methods and makes the intent of the methods a lot clearer. Now that I've gotten to play with it a little, I'm wondering what differences there may be between the async/await and the "classic" asynchronous callback syntaxes. Here are a few questions I have in mind, but there are numerous others that I won't have thought of now and probably will later. Does one perhaps offer superior performance

A code example illustrating the difference between the paradigms of async/await and Reactive (Rx) extension?

痞子三分冷 提交于 2019-12-20 08:39:02
问题 Both the System.Reactive extension for .NET and new C# 5.0 (.NET 4.5) async/await pursue (or based on) future and promises constructs paradigm (approach). Can you give the (*) simplest C# code example illustrating the difference between them? (*) Is it possible without I/O, internet or database connections? Update: Well, let me reformulate if this question seemed to be answered before. Why would one add and start using Reactive (Rx) extensions for .NET while using native .NET Iobservable

Wrapping synchronous code into asynchronous call

只愿长相守 提交于 2019-12-20 07:59:16
问题 I have a method in ASP.NET application, that consumes quite a lot of time to complete. A call to this method might occur up to 3 times during one user request, depending on the cache state and parameters that user provides. Each call takes about 1-2 seconds to complete. The method itself is synchronous call to the service and there is no possibility to override the implementation. So the synchronous call to the service looks something like the following: public OutputModel Calculate

Code coverage for async methods

旧时模样 提交于 2019-12-19 16:54:43
问题 When I analyse code coverage in Visual Studio 2012, any of the await lines in async methods are showing as not covered even though they are obviously executing since my tests are passing. The code coverage report says that the uncovered method is MoveNext , which is not present in my code (perhaps it's compiler-generated). Is there a way to fix code coverage reporting for async methods? Note : I just ran coverage using NCover, and the coverage numbers make a lot more sense using that tool. As

C# async/await strange behavior in console app

萝らか妹 提交于 2019-12-19 16:33:49
问题 I built some async/await demo console app and get strange result. Code: class Program { public static void BeginLongIO(Action act) { Console.WriteLine("In BeginLongIO start... {0} {1}", (DateTime.Now.Ticks - ticks) / TimeSpan.TicksPerMillisecond, Thread.CurrentThread.ManagedThreadId); Thread.Sleep(1000); act(); Console.WriteLine("In BeginLongIO end... \t{0} {1}", (DateTime.Now.Ticks - ticks) / TimeSpan.TicksPerMillisecond, Thread.CurrentThread.ManagedThreadId); } public static Int32 EndLongIO