Do the new C# 5.0 ‘async’ and ‘await’ keywords use multiple cores?

Two new keywords added to the C# 5.0 language are async and await, both of which work hand in hand to run a C# method asynchronously without blocking the calling thread. That gets across the purpose of the feature, but it gives too much “credit” to the async/await feature. Let me be very, very clear … Read more

Why doesn’t generic ICollection implement IReadOnlyCollection in .NET 4.5?

There are probably several reasons. Here are some: Huge backwards compatibility problems How would you write the definition of ICollection<T>? This looks natural: interface ICollection<T> : IReadOnlyCollection<T> { int Count { get; } } But it has a problem, because IReadOnlyCollection<T> also declares a Count property (the compiler will issue a warning here). Apart from … Read more

Difference between the TPL & async/await (Thread handling)

I believe the TPL (TaskFactory.Startnew) works similar to ThreadPool.QueueUserWorkItem in that it queues up work on a thread in the thread pool. Pretty much. From what i’ve been reading it seems like async/await only “sometimes” creates a new thread. Actually, it never does. If you want multithreading, you have to implement it yourself. There’s a … Read more

How to Async Files.ReadAllLines and await for results?

UPDATE: Async versions of File.ReadAll[Lines|Bytes|Text], File.AppendAll[Lines|Text] and File.WriteAll[Lines|Bytes|Text] have now been merged into .NET Core and shipped with .NET Core 2.0. They are also included in .NET Standard 2.1. Using Task.Run, which essentially is a wrapper for Task.Factory.StartNew, for asynchronous wrappers is a code smell. If you don’t want to waste a CPU thread by … Read more

Await in catch block

Update: C# 6.0 supports await in catch Old Answer: You can rewrite that code to move the await from the catch block using a flag: WebClient wc = new WebClient(); string result = null; bool downloadSucceeded; try { result = await wc.DownloadStringTaskAsync( new Uri( “http://badurl” ) ); downloadSucceeded = true; } catch { downloadSucceeded = … Read more

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