I recently moved to Visual Studio 2010 and upgraded my website to work with .NET Framework 4. (From VS 2008 - Framework 3.5)
What are things I need to know to improve site speed, readability or memory use?
I recently moved to Visual Studio 2010 and upgraded my website to work with .NET Framework 4. (From VS 2008 - Framework 3.5)
What are things I need to know to improve site speed, readability or memory use?
Parallel.For(0,10,(i)=>
{
// Do stuff in parallel.
});
The rest of the Parallel class provides some other great things like Parallel.Invoke(...)
and Parallel.ForEach(...)
.
Also, if you do anything with Linq, you can use the ParallelEnumerable.AsParallel() Method to convert your Linq queries to run in parallel.
It's all built on the Task Parallel Library which provides a great set of API's for working with tasks in an abstracted way that scales for whatever resources your machine has without having to think too much about exactly how many threads you are creating.
The way how C# implements event
fields is new. It no longer internally does a very bad lock (this)
by default. Events are still thread-safe however because an Interlocked.CompareExchange(...)
mechanism is now used instead.
This lead to some changes that could be breaking in some edge cases. More info:
Optional parameters is one of my favorites. The dynamic
type seems to be promising
For the sake of readability, I'll add my discovery as written in the question it self.
When using AJAX, you can specify EnableCdn property for the scriptManager to load values from CDNs (such as Microsoft CDN)
I believe there are also enhancements to WCF that eliminate previous annoyances like not being able to configure WebGet
/WebInvoke
differently for each endpoint in .Net 3.5. I believe it is fully configurable in 4.0.
For ASP.NET programmers the ASP.NET 4 and Visual Studio 2010 Web Development Overview white paper gives a comprehensive overview of what is new in ASP.NET 4. For a series of articles on the most prominent and interesting changes I'd recommend Scott Gutherie's series of blog posts on VS 2010 and .NET 4 Series.
I just love the fact that web.config file is small and meaningful, instead of long and full of unknown statements...
string.Join()
now has a signature that takes IEnumerable<T>
instead of just string[]
- a small improvement that allows you to rip out your .Select()
and .ToArray()
code.
Code contracts look very promising both from the standpoint of creating more correct code but also from the point of producing more complete documentation. Sadly they aren't all there in VS2010 yet - you have to install an add-on and even then it's neither complete nor finished and appears to still be a work in progress.
Awesome thing, Client IDs can be manipulated:
No more CTL0001$_DIV0003_TextBox1001$ or whatever...
I would also refer to original documentation (MSDN in this case) for a comprehensive list of improvements and additions:
http://msdn.microsoft.com/en-us/library/ms171868.aspx
From that article you can easily find the things that can improve the existing code base.
The DirectoryInfo
class in addition to the GetDirectories
and GetFiles
methods now has their lazy versions EnumerateDirectories
and EnumerateFiles
, which avoid us to have large arrays to hold all the objects at once.
The ASP.net cache is now in its own assembly!
System.runtime.caching.dll
which means you can use in other apps like WPF and WinForms without having to pull in the whole system.web assembly
I just wish they would have beefed up the CacheItem to include built-in information about the cache item like when it was added...when it will expire, etc
You can use memory-mapped files (in the same way that native Windows functions access memory-mapped files) to edit very large files and to create shared memory for interprocess communication. For a detailed explication see: http://msdn.microsoft.com/en-us/library/dd997372.aspx
System.Numerics.BigInteger - Represents an arbitrarily large signed integer.
System.Numerics.Complex - Represents a complex number.
Specific to ASP.NET MVC.
Instead of <%= Html.Encode(...) %>
You can do <%: ... %>
The colon syntax is short hand for Response.Write and HTML encoding in one. It sure does make your views nicer on the eyes.