multiple parallel async calls with await

The async/await includes a few operators to help with parallel composition, such as WhenAll and WhenAny. var taskA = someCall(); // Note: no await var taskB = anotherCall(); // Note: no await // Wait for both tasks to complete. await Task.WhenAll(taskA, taskB); // Retrieve the results. var resultA = taskA.Result; var resultB = taskB.Result;

Does the use of async/await create a new thread?

In short NO From Asynchronous Programming with Async and Await : Threads 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 … Read more

Using async without await?

You still are misunderstanding async. The async keyword does not mean “run on another thread”. To push some code onto another thread, you need to do it explicitly, e.g., Task.Run: await Task.Run(() => Logger.LogInfo(“Pushing new call {0} with {1} id”.Fill(callNotificationInfo.CallerId)); I have an async/await intro post that you may find helpful.

Is async/await suitable for methods that are both IO and CPU bound?

There are two good answers already, but to add my 0.02… If you’re talking about consuming asynchronous operations, async/await works excellently for both I/O-bound and CPU-bound. I think the MSDN docs do have a slight slant towards producing asynchronous operations, in which case you do want to use TaskCompletionSource (or similar) for I/O-bound and Task.Run … Read more

Error CS1056: Unexpected character ‘$’ running the msbuild on a tfs continuous integration process

The problem can be fixed installing a Nuget package Microsoft.Net.Compilers. Below is the link of my highlighted answer: Project builds fine with Visual Studio but fails from the command line That feature is a syntactic sugar for C#6, try to install the latest version of the framework 4.6.2 https://www.microsoft.com/en-us/download/details.aspx?id=53345 Then go to your Project properties … Read more

Explicitly use a Func for asynchronous lambda function when Action overload is available

Because Task.Run has signatures of both Task.Run(Func<Task>) and Task.Run(Action), what type is the async anonymous function compiled to? An async void or a Func<Task>? My gut feeling says it will compile down to an async void purely because its a non-generic type however the C# Compiler might be smart and give Func<Task> types preference. The … Read more

call async method without await #2

If you call an async method from a single threaded execution context, such as a UI thread, and wait for the result synchronously, there is a high probability for deadlock. In your example, that probability is 100% Think about it. What happens when you call ValidateRequestAsync(userName, password).Result You call the method ValidateRequestAsync. In there you … Read more

Task.Yield – real usages?

When you see: await Task.Yield(); you can think about it this way: await Task.Factory.StartNew( () => {}, CancellationToken.None, TaskCreationOptions.None, SynchronizationContext.Current != null? TaskScheduler.FromCurrentSynchronizationContext(): TaskScheduler.Current); All this does is makes sure the continuation will happen asynchronously in the future. By asynchronously I mean that the execution control will return to the caller of the async method, … Read more

What is [NotifyPropertyChangedInvocator] in C# when implements INotifyPropertyChanged?

It is a Resharper attribute from their Annotations – designed to give you warning then your code looks suspicious 🙂 Consider this: public class Foo : INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; [NotifyPropertyChangedInvocator] protected virtual void NotifyChanged(string propertyName) { … } private string _name; public string Name { get { return _name; } set { … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)