What is the difference between await Task and Task.Result?

I wont be wrong if I think that await will release the calling thread but Task.Result will block it, would it be right? Generally, yes. await task; will “yield” the current thread. task.Result will block the current thread. await is an asynchronous wait; Result is a blocking wait. There’s another more minor difference: if the … Read more

Understanding async / await in C#

I recommend you start out with my intro to async/await and follow-up with the official Microsoft documentation on TAP. As I mention in my intro blog post, there are several Task members that are holdovers from the TPL and have no use in pure async code. new Task and Task.Start should be replaced with Task.Run … Read more

MEF with MVC 4 or 5 – Pluggable Architecture (2014)

I have worked on a project that had similar pluggable architecture like the one you described and it used the same technologies ASP.NET MVC and MEF. We had a host ASP.NET MVC application that handled the authentication, authorization and all requests. Our plugins(modules) were copied to a sub-folder of it. The plugins also were ASP.NET … Read more

AddIdentity vs AddIdentityCore

AddIdentityCore adds the services that are necessary for user-management actions, such as creating users, hashing passwords, etc. Here’s the relevant source: public static IdentityBuilder AddIdentityCore<TUser>(this IServiceCollection services, Action<IdentityOptions> setupAction) where TUser : class { // Services identity depends on services.AddOptions().AddLogging(); // Services used by identity services.TryAddScoped<IUserValidator<TUser>, UserValidator<TUser>>(); services.TryAddScoped<IPasswordValidator<TUser>, PasswordValidator<TUser>>(); services.TryAddScoped<IPasswordHasher<TUser>, PasswordHasher<TUser>>(); services.TryAddScoped<ILookupNormalizer, UpperInvariantLookupNormalizer>(); // No … Read more

Retrieving Dictionary Value Best Practices

TryGetValue is slightly faster, because FindEntry will only be called once. How much faster? It depends on the dataset at hand. When you call the Contains method, Dictionary does an internal search to find its index. If it returns true, you need another index search to get the actual value. When you use TryGetValue, it … Read more

Huge performance difference (26x faster) when compiling for 32 and 64 bits

I can reproduce this on 4.5.2. No RyuJIT here. Both x86 and x64 disassemblies look reasonable. Range checks and so on are the same. The same basic structure. No loop unrolling. x86 uses a different set of float instructions. The performance of these instructions seems to be comparable with the x64 instructions except for the … Read more