ThreadPool.QueueUserWorkItem vs Task.Factory.StartNew

If you’re going to start a long-running task with TPL, you should specify TaskCreationOptions.LongRunning, which will mean it doesn’t schedule it on the thread-pool. (EDIT: As noted in comments, this is a scheduler-specific decision, and isn’t a hard and fast guarantee, but I’d hope that any sensible production scheduler would avoid scheduling long-running tasks on … Read more

Error – The transaction associated with the current connection has completed but has not been disposed

This can happen when the transaction times out. You can increase the timeout for your transaction like this (use values appropriate for the expected length of your transaction). The code below is for 15 minutes: using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, new System.TimeSpan(0, 15, 0))) { // working code here } This is why it … Read more

C#: Dynamic runtime cast

I think you’re confusing the issues of casting and converting here. Casting: The act of changing the type of a reference which points to an object. Either moving up or down the object hierarchy or to an implemented interface Converting: Creating a new object from the original source object of a different type and accessing … Read more

C# ‘dynamic’ cannot access properties from anonymous types declared in another assembly

I believe the problem is that the anonymous type is generated as internal, so the binder doesn’t really “know” about it as such. Try using ExpandoObject instead: public static dynamic GetValues() { dynamic expando = new ExpandoObject(); expando.Name = “Michael”; expando.Age = 20; return expando; } I know that’s somewhat ugly, but it’s the best … Read more

System.Runtime.Caching.MemoryCache vs HttpRuntime.Cache – are there any differences?

HttpRuntime.Cache gets the Cache for the current application. The MemoryCache class is similar to the ASP.NET Cache class. The MemoryCache class has many properties and methods for accessing the cache that will be familiar to you if you have used the ASP.NET Cache class. The main difference between HttpRuntime.Cache and MemoryCache is that the latter … Read more

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