Development

TCP servers with .NET: Scenario 1 - Simple TCP servers

Submitted by Robert MacLean on Wed, 11/16/2011 - 10:50

This post is part of a series, to see the other posts in the series go to the series index.

imageWriting a TCP server is something that modern business .NET developers do not need to worry about, we have WCF which has abstracted us from understanding TCP servers & clients for business apps – but for some systems we still need to write a TCP server or client.

Microsoft has optimised the .NET framework for common scenarios – for example doing something like SMTP where a server where it is always running and clients connect when they have data, provide the data and disconnect. So what you may do is start a server (in it’s own thread so you can still do other things in the app), and wait for client connections. At this point you are blocking processing until a client connects. When a client connects, you get the data and process it (in a new thread, so you can allow more clients to connect).

The advantage of this is this is a simple model and is fairly easy to setup, but there is a few problems with this:

  1. You have this blocking point while you wait for clients, so trying to shut it down is difficult. As the view of a server is that it should always be up, this is not an optimised path so there is no way. Basically you will need to deal with task manager to kill the process.
  2. You have lots of threading and you must handle threads. Threads are hard to understand and easy to fail so we are opening up potential for problems.
  3. You assume the client will connect and send data at once and will go away. Once again this is the “normal” scenario (think HTTP or SMTP) but there are scenarios where this is not possible.

Below is the sample to do this in a console application.

class Program
{
    private const int BufferSize = 4096;
    private static bool ServerRunning = true;

    static void Main(string[] args)
    {
        new Thread(RunTCPServer).Start();
        Console.WriteLine("Press enter to shutdown");
        Console.ReadLine();
        ServerRunning = false;
    }

    private static void RunTCPServer()
    {
        var tcpServer = new TcpListener(IPAddress.Any, 9000);
        try
        {
            tcpServer.Start();
            while (ServerRunning)
            {
                var tcpClientConnection = tcpServer.AcceptTcpClient();
                Console.WriteLine("Client connection");

                // spawn thread to deal with it     
                new Thread(ClientConnection).Start(tcpClientConnection);
            }
        }
        finally
        {
            tcpServer.Stop();
        }
    }

    private static void ClientConnection(object state)
    {
        var tcpClientConnection = state as TcpClient;
        var stream = tcpClientConnection.GetStream();
        var buffer = new byte[BufferSize];

        var amountRead = stream.Read(buffer, 0, BufferSize);
        var message = Encoding.ASCII.GetString(buffer, 0, amountRead);
        Console.WriteLine("Client sent: {0}", message);
    }
}

The Arturo Grid for Windows Phone 7 in PNG & GIMP

Submitted by Robert MacLean on Wed, 10/26/2011 - 07:38

layoutArturo Toledo works at Microsoft on the Windows Phone Design Studio team, and last week I had the chance to attend phone training with him. In that training he showed a grid he used for layout so that his apps match the layout of Windows Phone 7 apps – I call this the Arturo Grid.

Yesterday he posted about it and released an Expression Design version of it, which is great if you have Expression Design… but if you don’t it can be a problem. So I recreated it using the free graphics tool, The GIMP, and produced a transparent PNG version so that it can work in just about anything!

Downloads

How I did it?

GIMP is a fantastic tool and I thought I would share how I created this layout. First I started with a new image, with the resolution of 480 x 800 and a transparent background.

image

Next run FiltersRenderPatternGrid and set the parameters as in the screen shot below. Note the offset horizontal & vertical lines are not linked. What we are doing here are creating grids of 37x37 (25 + 12 based off the Arturo Grid) with line width of 12 (so the space that is left is 25x25). The offset is +6 so that it pushes out, because the line widths are based on the middle of the line and not the edge.

image

Now add two layers, another transparent one and a white backed layer.

image

Place the new transparent at the bottom and the white in second place.

image

and now merge down the grid layer onto the white layer.

image

Now drag on guides:

  • Vertical: 24px
  • Vertical: 456px
  • Horizontal: 56px
  • Horizontal: 784px

and select that region.

image

Create a new

Then use Select ► Invert and press delete. This removes the area around the grid for the bleed (padding) area that your app shouldn’t use.

image

Now use the Fuzzy Select Tool (aka the magic wand selector tool) and click on the black.

image

Now hit delete to remove those black lines leaving just the white squares.

image

You can tweak the colours using the colour exchange tool (Colors ► Map Color ► Exchange) and you can tweak the transparency using the Opacity option on the layer tool to make it more transparent.

image

There you go, now you are done Smile

image

Tech·Ed Africa: Slides, Scripts & Thoughts

Submitted by Robert MacLean on Wed, 10/19/2011 - 10:46

WP_000405WOW! I am sitting here under s a fake tree in a fake city that is Micropolis (also known as the Tech·Ed Africa 2011 expo, and it is AMAZING!). I have just finished my third and final presentation at Tech·Ed Africa 2011 and I just wanted to say THANK YOU THANK YOU THANK YOU THANK YOU THANK YOU THANK YOU THANK YOU THANK YOU THANK YOU THANK YOU THANK YOU THANK YOU THANK YOU THANK YOU THANK YOU THANK YOU THANK YOU THANK YOU to all the people who attended my talks!

This year not only has an amazing expo, but the audiences have been by far the BEST EVER! A special thanks to those who braved 8am to see my .NET 4 talk – 2min before I started I thought “I need sleep”, 2min after the energy from the audience was flowing and I never looked back at what I felt was a great talk, so thank you! Smile

what it looks like from the presenter at #techedafricaA special work of thanks to Suliman and DPE (it is their fake tree I am sitting under) for arranging this and the opportunity to present! I also want to say thanks to the technical team at the event, without who you would not see or hear me, and they were fantastic this year!

For those who attended my talks, or those who couldn’t below are the slides, scripts and misc files used in the talks!

(for those in an RSS reader or on the home page, click read more)



Power features in .NET 4: Investigating the features of .NET 4 which you don’t know about

File downloads

Extend Visual Studio 2010

File downloads

Building Business Applications with Microsoft Visual Studio LightSwitch

File downloads

SharePoint Saturday: Lab Rooms

Submitted by Robert MacLean on Fri, 10/07/2011 - 13:24

imagelogo_wp75-h_webNext weekend (15th Oct) Cape Town is hosting the SharePoint Saturday conference and myself and fellow BBDer Rudi Grobler will be there and will be and we are running a very special event in conjunction with the main event: Lab Rooms!

There will be two special rooms available and in one Rudi will presenting and training on Windows Phone 7 and in the other I will be presenting and training on the Windows Azure Platform!

The cost for this? FREE! It is being sponsored by BBD & the SharePoint Saturday event Smile

Space in both rooms is VERY VERY limited, so you need to register NOW!

Windows Phone Registration: http://wp7camp.eventbrite.com/

Windows Azure Registration: http://windowsazurecpt.eventbrite.com/

Windows 8: How to get it working

Submitted by Robert MacLean on Thu, 09/15/2011 - 14:09

(Update 1) Note: This relates to the Windows 8 Developer Preview, your mileage may vary and this may change.

This post is here to help you, and me, by sharing solutions that I am finding while trying to get Windows 8 running for a professional developer. I am using a HP 8510w laptop so some things maybe specific. This will be updated randomly and will be more like a live blog than a polished post.

(Update 1) As I update this I will prefix new content with (Update #) where # is the update number. The latest ones will be in bold.

Problems & Solutions

Graphics

I have a NVidia Quatro graphics card and to get it working correctly with Win8 (rather than the basic graphic driver) I needed to use the BETA driver from: Beta and Older Driver Versions – I used the Verde 285.27 Driver and that worked just fine, everything else was broken in one way or another.

(Update 5) This just worked with the Windows 8 Community Preview

.NET 3.5

imageA bunch of apps use .NET 3.5 or earlier so I needed that. To install it you must install it via the Turn Windows Features On/Off  option in the control panel (it’s under Programs). I had a BUNCH of issues (error 0x800F0906) getting it to work as it needs to download it which I think are proxy related. Once I downloaded via 3g it finally came down (took an hour Sad smile).

(UPDATE 2) Tried this via a transparent proxy and it worked too. Seems it is related to proxy servers that require basic authentication.

(UPDATE 4) Finally found a solution Smile Thanks to Zayd Kara for helping me with this:

Copy the SXS folder from the Windows 8 ISO to the C:\Temp folder.

Then run: dism.exe /online /enable-feature /featurename:NetFX3 /All /Source:c:\temp\sxs /LimitAccess

pic

Metro Style Apps Don’t Run

Details: http://social.msdn.microsoft.com/Forums/en-US/windowsdeveloperpreviewgeneral/thread/cd6df64d-737d-40e0-b999-03e654204448

(Update 1) Found the error message in the Event Log (Application and Services Logs –> Microsoft –> Windows –> WwaHost –> Admin)

Windows Web Application Host has encountered an unexpected exception. The error is number 0x8007000E.

image

(UPDATE 2) One of the best new features in Windows 8 is the ability to reset your machine without affecting your files. I did this and this solved all my issues image

(UPDATE 4) The cause of this is the DLink modem software for my 3G modem. It is screwing up com. No idea why, and no way around it. That’ll teach me to use a 3g modem that doesn’t work with the natively Windows 7/8 mobile internet support.

Windows Phone Developer Tools

The 7.0 RTM release will NOT install at all. The 7.1 RC will install so you may need to get that one.

YOU MUST install .NET 3.5 first (see above). Once installed I didn’t have any emulator options and trying to run it would cause: HRESULT: 0x89721800

I resolved this by deleting “%LOCALAPPDATA%\Microsoft\Phone Tools\CoreCon\10.0” (source for that App Hub Forums)

The emulator option appeared but now when I try to run it, it crashes Windows 8 with a BSOD related to vmm.sys – no solution yet.

(UPDATE 2) I have tried everything and nothing seems to help. Resorted to using a Windows 7 boot from VHD to be able to run these tools Sad smile

(Update 5) Solved: http://sadev.co.za/content/installing-windows-phone-developer-tools-windows-8

Microsoft Security Essentials

It would not install because of a compatibility issue Sad smile Downloaded it again from the website, which doesn’t tell you version numbers and the file size looked the same, but this newer one did work fine.

(UPDATE 2) Paul Adare pointed out on the forums that this is included now out of the box, so not needed Smile 

Switch to Live ID

Not working, error 0xD00000072 – suspecting proxy again.

Install of Visual Studio 2010 Offline Documentation

Completely failed, no idea why.

Capture

D-Link 3G Modem

It could not find the drivers, so I had to go to device manager, select the unknown devices –> Right click –>  Update Driver –> Browse my computer –> C:\Program Files (x86)\D-Link Connection Manager\drivers\64bit\WIN7

Then it found and installed the drivers for the 3G modem

(Update 1) Visual Studio 11 Express for Windows Developer Preview

Cannot build or run Metro Style apps.

Designer is failing with Server execution failed (Exception from HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE))

And running them fails with Unable to activate Windows Tailored application

I suspect this is related to the Metro app issue above.

Capture5Capture6

(Update 1) Internet Explorer 10

Two interesting issues, one browsing our intranet which runs on HTTPS any content from HTTP fails to load and there is NO option to allow it.

Capture3

Second issue is in the IE desktop mode there is no tooltips Confused smile 

ie-desktop

However the solution is to run the Metro Style Internet Explorer, and it shows tooltips… and they are LOVELY:

ie-metro

(Update 3) SharePoint

I am referring to connecting to SharePoint server using IE 10, in short – it is horrid for anything other than basic browsing. I have installed Chrome to get around this.

(Update 3) Windows Server AppFabric

imageI needed Windows Server AppFabric installed so I could do development, however AppFabric does not install on Windows 8 Sad smile

To work around this I waited for the error to appear, then browsed to the extracted files (the moment you click ok on the error it cleans itself up) and used the expand command to extract the msu file which you can find in the packages folder.

That gets me a cab file which I extract again and that produces another 1 996 files. In there I used the file search to find the assemblies I needed to get the code to build, won’t run but at least I can code Smile

(Update 4) HP LaserJet 4250 Printer

I have this printer on the network but it was horrid trying to get Windows to see and work with it. The trick was to download the actual PCL6 drivers from the HP website. This has all the options to set it up and it works fine now Smile

(Update 5) This just worked with the Windows 8 Community Preview

Things that just worked

For balance here are application that have been installed with no issue.

  • Visual Studio 2010 + SP1
  • Firefox 6
  • Chrome (what ever the latest is)
  • Windows Live Writer
  • TweetDeck
  • Office 2010 + SP 1
  • (Update 1) VLC
  • (Update 3) Pull

There is also some more info in the comments!

Windows Phone 7 Weekend Workshop

Submitted by Robert MacLean on Thu, 09/08/2011 - 16:00

I have mentioned an awesome event that is being run by Microsoft before, the Windows Phone 7 Weekend Workshop and I just want to highlight it again (it is about 70% full already so you need to hurry up).

It is a FREE full day event with TWO tracks available. There is a lecture/presentation style track where you learn about the phone and a developer room track where you can build your phone apps with expert guidance or do some hands on labs. 

I am most excited about the developer room, because if you want to get an up out to the market place THIS IS THE BEST PLACE TO BE. Expert help, focused time and who knows, maybe some prizes for those who get them up!

The event is being run in conjunction with a number of groups

  • Microsoft – Being just after //BUILD may be a GREAT time to get some extra insight or clarity.
  • Nokia – You know the phone guys, they are sponsoring this event and will have someone there to answer questions.
  • BBD & MVP – Both myself & Rudi Grobler are speaking and we both work at BBD & are both Microsoft MVP’s.

Details:

.NET 4, do you know the new features? - Top 10 most useful features

Submitted by Robert MacLean on Thu, 09/08/2011 - 10:05

image

More in this series can be found in the introduction.

In the past two posts we have looked at the negative (top 10 least known, top 12 most useless) so lets switch to the positive side and see what is on the list for top 10 most useful features.

This is worked out by those who knew the feature and indicated it was useful using the same ratio as explained in the in top 12 most useless post.

CLR/BCL: IsNullOrWhiteSpace

Useful Ratio: 21 : 1

Introduction: We have had IsNullOrEmpty on string for a while but in .NET 4 we have the added IsNullOrWhiteSpace which checks for Nulls, empty strings or strings of just white space.

Thoughts: Easy to see why this is useful, it covers more scenarios than the old one, it is easily discoverable and it solves a difficult problem (I do not think many people understand all the white space charters).

More Info: http://www.sadev.co.za/content/net-4-baby-steps-part-ii-string

CLR/BCL: Stream.CopyTo

Useful Ratio: 19 : 1

Introduction: You have two streams, you want to copy from one stream to another one, which previously took 6 lines of code, a loop and 3 variables now uses 1 line of code and always works.

Thoughts: A common problem and a great solution and is easily discoverable because the method name is exactly what you would be looking for.

More Info: http://www.sadev.co.za/content/net-4-baby-steps-part-ix-stream

CLR/BCL: Enum.HasFlag

Useful Ratio: 17 : 1

Introduction: Enumerator has support for bitwise operations but previously has involved a fairly unintuitive calculation. I think that it was so unintuitive that some people have never even realised bitwise operations were supported. Now we have a single method which makes it VERY easy.

Thoughts: Making the hard easy and making it very discoverable – the factors of all these top useful functions!

More Info: http://www.sadev.co.za/content/net-4-baby-steps-part-iii-enum

CLR/BCL: Enum.TryParse

Useful Ratio: 7.6 : 1

Introduction: Going from a string to an enum has been possible in the past but it has never been a fluid experience. No support for generics and not easy to to handle bad data easily. TryParse solves those by brining generics into it and providing a response to tell you if it succeeds.

Thoughts: I think this is a BIG problem for many developers and this is a great and useful solution.

More Info: http://www.sadev.co.za/content/net-4-baby-steps-part-iii-enum

CLR/BCL: TimeSpan parsing improvements

Useful Ratio: 5.7 : 1

Introduction: Parsing strings into timespans is not easy, there is many ways to type in time ranges and it has been difficult for people to get right constantly… until .NET 4!

Thoughts: I am surprised at how highly this is up the list, it is useful but ranked this high surprises me as I do not think many people use TimeSpan’s in business systems.

Update: Mark Stacey on Twitter provided some good business use cases I didn't think of (Tweet 1, Tweet 2): "Absolutely. Business process stuff ~ loan applications, time since call was logged, tons of others. Especially where multiple applications work in process."

More Info: http://www.sadev.co.za/content/net-4-baby-steps-part-i-timespan

CLR/BCL: MemoryCache

Useful Ratio: 5 : 1

Introduction: MemoryCache is a per process in memory cache for your application which is VERY easy to use regardless of application type – prior to .NET 4 only ASP.NET had an in memory cache. There is also some low plumbing that makes it possible to have the cache stored to other locations, like files or SQL.

Thoughts: This is one of only two features in this list that also appeared in another list, in both cases the top 10 unknown features. This brings joy to me since it means that the issue here is discoverability because once you know it – you find big value in it Smile

More Info: http://www.sadev.co.za/content/net-baby-steps-part-vii-caching

CLR/BCL: string.Join

Useful Ratio: 4.7 : 1

Introduction: Join allows us to concatenate an array of strings together with a specific separator character in place.

Thoughts: This is very useful, as there is often times you need to loop over strings and build up another string. Think of in line SQL generation with a WHERE clause! Very useful stuff.

More Info: http://www.sadev.co.za/content/net-4-baby-steps-part-ii-string

Parallel: Parallel Extensions

Useful Ratio: 3.7 : 1

Introduction: Writing code that runs across cores has not been easy and the parallel extensions make it easy to understand how when thinking about normal for or foreach looping structures as it provides implementations of those looping structures which do run across multiple cores.

Thoughts: A fantastic edition to the framework and a much needed one to help solve the issue of having multi-core machines but the complexity of threading not being worth the effort. Why this is came in so high compared to the other two new additions in parallel (TPL was ranked 14th most useful & PLINQ 22nd) is odd but maybe because this is the easiest of the three to understand.

As a side not this is the only one of the most useful top 11 that I didn’t cover in my .NET 4 Baby Steps series which really makes me proud since it shows I was on target for that series.

More Info: http://www.sadev.co.za/content/pulled-apart-part-vii-plinq-not-easy-first-assumed

CLR/BCL: 64bit identification on Environment class

Useful Ratio: 3.5 : 1

Introduction: The environment class has been enhanced to have two new properties which help if the OS is 64bit and the process running is 64bit.

Thoughts: This also appeared on the top 10 unknown feature list, so really highlights that developers are either not thinking about 64bit at all but when they do, the tools they need are available.

More Info: http://www.sadev.co.za/content/net-4-baby-steps-part-xiii-tiny-steps

CLR/BCL: Lazy

Useful Ratio: 3.2 : 1

Introduction: Lazy allows you to wrap a class (target class) in another class (Lazy<T> class) and gain lazy constructor calling on the target class.

Thoughts: Very nice feature, but I am surprised it did this well on the useful list as I see this as a bandage to a bad design solution. Proper use of patterns and planning in code should prevent usage – but I’ve been known to be wrong so tell me in the comments why you see this as useful!

More Info: http://www.sadev.co.za/content/net-4-baby-steps-part-v-lazy

.NET 4, do you know the new features? - The 12 features the majority thinks are useless.

Submitted by Robert MacLean on Wed, 09/07/2011 - 08:59

image

More in this series can be found in the introduction.

Another interesting statistic was that only 12 of the 61 features are rated useless, in other words more people thought those features were useless than useful.

This is really good, because this really means that about 80% of the new features are seen to be useful and thus that was a good spend of resources for Microsoft.

I am measuring this in a Useful Ratio – Number of people who think it is useful compared to number of people who think it is useless. For examples:

  • 1 : 1 – For every one person who thinks it is useful, one person thinks it is useless
  • 2 : 1 – Two people think it is useful for everyone that thinks it isn’t.
  • 0.5 : 1 – Half a person thinks a feature is useful compared for everyone who thinks it is useless.

CLR/BCL: Addition & Subtraction with IntPtr & UIntPtr

Useful Ratio: 0.3 : 1

Introduction: Adds an offset to the value of a pointer.

Thoughts: The first feature to appear on more than one list, as it also appeared on the top 10 least known. So this brings up an interesting though – you either don’t know of this or you think it is shit. My views of why this is useless is the same as why it is unknown, the use case for this is TINY!

More Info: http://msdn.microsoft.com/en-us/library/system.intptr.op_addition.aspx

CLR/BCL: Complex Number Support

Useful Ratio: 0.3 : 1

Introduction: Complex numbers are a specific mathematical concept especially for doing graphs, vector calculus and other things that are pretty specialised.

Thoughts: .NET 4 also included another new construct called Tuple and .NET has had KeyValuePair for ages and this seems very similar to those (from the perspective of someone without university math). All it gives compared to the other two are some easier math functions. So easy to see why it is not that useful as it is easy to implement those on Tuple or KeyValuePair.

More Info: http://www.sadev.co.za/content/net-4-baby-steps-part-xii-numbers

WPF: Touch Support

Useful Ratio: 0.4 : 1

Introduction: WPF now supports input from touch, like you can touch buttons and text boxes etc…

Thoughts: This feels very similar to System.Device.Location which is hampered by the lack of hardware that supports the feature.  WPF is doubly hurt because Silverlight is competing with it and has touch support already.

More Info: http://blogs.msdn.com/b/jaimer/archive/2009/11/04/introduction-to-wpf-4-multitouch.aspx

CLR/BCL: Side by Side (SxS) CLR's in the same process

Useful Ratio: 0.6 : 1

Introduction: Prior to .NET 4 you could not allow two different CLRs (i.e: 1.0, 1.1 or 2.0) in exist in the same process.

Thoughts: I hit this a few times with ASP.NET where two sites ran in the same AppPool and one site was running 1.1 and the other 2.0 and there would be a failure.

This was primarily put in also to allow plug-ins built in different CLR’s run in the same application.

Besides the ASP.NET issue I’ve not seen a need for this, it really feels like plumbing for future applications.

Update: Mike posted in the comments a great use case I didn't think of, which adds more value for this feature.

More Info: http://msdn.microsoft.com/en-us/magazine/ee819091.aspx

WPF: Text Rendering Stack

Useful Ratio: 0.6 : 1

Introduction: WPF previously rendered text differently to how Windows did, this is where the perception of it being blurry comes from. As part of Visual Studio 2010 they used WPF and spent considerable time improving the text rendering.

Thoughts: I don’t get this, it means that WPF is better looking and it costs nothing for you. Maybe the issue is because it costs nothing people see the value as nothing?

More Info: http://www.hanselman.com/blog/WPFAndTextBlurrinessNowWithCompleteClarity.aspx

ASP.NET: CDN Support

Useful Ratio: 0.7 : 1

Introduction: Microsoft has a large content delivery network which contains many scripts that web sites use, like jQuery. Using a CDN can significantly improve performance of your website.

Thoughts: Reasons why I think people don’t like this:

  • Internal only applications cannot benefit from this.
  • People prefer other CDN’s – as there are a few BIG ones now.
  • People don’t trust a CDN

If you can use this this, you should, it is a simple switch to turn it on.

More Info: http://www.asp.net/ajaxlibrary/cdn.ashx

CLR/BCL: ETW Support

Useful Ratio: 0.8 : 1

Introduction: ETW, Event Tracing for Windows, is a feature of Windows for doing logging at the kernel level. It is brilliant as you can do THOUSANDS of messages per second with VERY low CPU usage. With .NET 4 we have CLR support for this so understanding what is happening in the CLR along with our applications becomes very easy.

Thoughts: We have been able to write to ETW since .NET 3.0 – all this is is support for the CLR events, so really you need to be debugging performance issues in the CLR.

More Info: http://naveensrinivasan.com/2010/03/17/using-clr-4-0-event-tracing-for-windows-etw-along-with-application-etw/

ASP.NET: Grid & List Row Selection Persistence

Useful Ratio: 0.8 : 1

Introduction: Allows the selected row in a list or grid to be persisted automatically over post backs.

Thoughts: Simple for why this is not seen as useful: People who care use ASP.NET MVC

More Info: http://www.asp.net/aspnet-4/videos/aspnet-4-quick-hit-persistent-gridview-row-selection

CLR/BCL: Primary Interop Assembly Embedding

Useful Ratio: 0.9 : 1

Introduction: PIA’s (Primary Interop Assemblies) are mappings between COM+ API’s and .NET. Similar to header files in C. These are exposed as separate assemblies and in .NET 4 you can embed just the code you use in your assembly as part of the build rather than requiring the separate assemblies.

Thoughts: I don’t think this is important at all – we have learnt to include the assemblies we need with our solution so embedding code is just a solution to a problem that didn’t exist.

More Info: http://www.hanselman.com/blog/CLRAndDLRAndBCLOhMyWhirlwindTourAroundNET4AndVisualStudio2010Beta1.aspx

CLR/BCL: SortedSet

Useful Ratio: 0.9 : 1

Introduction: SortedSet is a class for doing sorting, similar to SortedList or SortedDictionary. However where the old ones internally use a hash table, this uses a binary tree and thus gets some FANTASIC performance in many situations where the others would have bad perf.

Thoughts: I don’t think there is enough understanding of patterns with .NET developers – we are too quick to just use what Microsoft gives us and move along. So there isn’t enough people thinking about the pattern for their data structures so they see this as a solution to a solved problem. Those that do care, already have built their own code for this problem.

More Info: http://www.sadev.co.za/content/net-4-baby-steps-part-vi-sortedset

WPF: Windows 7 Integration (System.Windows.Shell)

Useful Ratio: 0.9 : 1

Introduction: Building a WPF application and want to take advantage of new Windows 7 features like the taskbar, quick launch or overlays? It is easy with the System.Windows.Shell.

Thoughts: I don’t get why this isn’t more popular, it is a VERY useful set of tools. Maybe people just don’t like WPF?

More Info: Rudi Grobler has a series on this:

ASP.NET: Routing for WebForms

Useful Ratio: 0.9 : 1

Introduction: ASP.NET MVC brought us routing support so that we can direct URL’s to specific content based on a convention or a configuration. With .NET 4 we get support for this in WebForms.

Thoughts: WebForm developers don’t care about this, they have never needed it and don’t need it now. I see the big market for this is actually hybrid scenarios where you using WebForms and MVC in the same system… a VERY small market.

More Info: http://msdn.microsoft.com/en-us/magazine/dd347546.aspx

.NET 4, do you know the new features? - Top 10 Least Known Features

Submitted by Robert MacLean on Tue, 09/06/2011 - 12:20
More in this series can be found in the introduction.

image_thumb[2]We start off with the features that people just did not know about. I measured this on percentage, i.e. percentage of people who answered that they did not know about feature X.

The top 10 features in the dark are:

CLR/BCL: Microsoft.Win32.RegistryView

Percentage of People that Didn’t Know (PPDK): 90%

Introduction: On the 64-bit version of Windows, portions of the registry are stored separately for 32-bit and 64-bit applications. There is a 32-bit view for 32-bit applications and a 64-bit view for 64-bit applications.

Thoughts: If you just write to or read from the registry in your application you do not need to specify this. This means this feature is really only needed by people opening registry values for Windows or other applications, a very specific usage, so not surprised by this finding.

More detail: http://msdn.microsoft.com/en-us/library/microsoft.win32.registryview.aspx

CLR/BCL: Addition & Subtraction with IntPtr & UIntPtr

PPDK: 85%

Introduction: Adds an offset to the value of a pointer.

Thoughts: I can’t think of a scenario for the usage of this that most business application devs would care about – maybe it is useful doing interop or game dev. So not surprising it very unknown.

More detail: http://msdn.microsoft.com/en-us/library/system.intptr.op_addition.aspx

CLR/BCL: System.Device.Location

PPDK: 84%

Introduction: Allows you to talk to GPS sensors that Windows 7 supports.

Thoughts: Most Windows 7 machines, laptops, desktops etc… do not have a built in GPS yet so not surprising this isn’t well known. It is a pity since it is an awesome feature to include in applications and can work with a software GPS like GeoSense for Windows.

More detail: http://www.sadev.co.za/content/net-4-baby-steps-part-x-location-location-location

CLR/BCL: 64bit identification on Environment class

PPDK: 83%

Introduction: There is two new Boolean properties on System.Environment, one tells if the OS is 64bit and the if the process is 64bit.

Thoughts: Not sure why this isn’t better known – maybe people just don’t care about 64bit vs. 32bit or maybe people are not optimising for the operating system.

More detail: http://www.sadev.co.za/content/net-4-baby-steps-part-xiii-tiny-steps

CLR/BCL: Improved NGen sub-system

PPDK: 82%

Introduction: NGen is the sub-system or command line which compiles your assemblies from IL to machine code and can result in start up performance improvements.

Thoughts: This is a very specialised system and I have never seen anyone except Microsoft use it. So not surprised at all that people do not know of it.

More detail: http://blogs.msdn.com/b/clrcodegeneration/archive/2009/05/03/improvements-to-ngen-in-.net-framework-4.aspx

CLR/BCL: New options in Environment.SpecialFolder

PPDK: 80%

Introduction: This is used to help find the path to those special folders (think My Documents, which changes from profile to profile for example) and is used in conjunction with the GetFolderPath (see below).

Thoughts: There 25 new options, and some are just useless (Windows & Fonts for example: if you know the System drive they are ALWAYS <system drive>:\Windows & <system drive>:\Windows\Font respectively this is because Windows is has to be installed to a folder called Windows), but many others are very good and useful especially the x86 specific folders if you on a x64 OS & support for new Windows 7 features, like common folders.

So why it is so unknown is beyond me – this is GOOD STUFF!

More detail: http://www.sadev.co.za/content/net-4-baby-steps-part-xi-special-folders

CLR/BCL: ETW Support

PPDK: 80%

Introduction: ETW, Event Tracing for Windows, is a feature of Windows for doing logging at the kernel level. It is brilliant as you can do THOUSANDS of messages per second with VERY low CPU usage. With .NET 4 we have support for this in our applications and support to log information from the framework, like garbage collections.

Thoughts: Even though this is brilliant and powerful but logging is solved problem. So this really is only used or needed by people with some massive performance issues and I do not believe most developers are working on solutions at that scale.

More detail: http://naveensrinivasan.com/2010/03/17/using-clr-4-0-event-tracing-for-windows-etw-along-with-application-etw/

CLR/BCL: GetFolderPath improvements

PPDK: 80%

Introduction: GetFolderPath is used with Environment.SpecialFolder (above) and the improvements to create the folder and control verification if the folder is created.

Thoughts: The GetFolderPath additions are a new overload so if you were using it prior to .NET 4 it may look the exact same, so this could just be a discoverability issue.

More detail: http://www.sadev.co.za/content/net-4-baby-steps-part-xi-special-folders

CLR/BCL: MemoryCache

PPDK: 79%

Introduction: MemoryCache is a per process in memory cache for your application which is VERY easy to use regardless of application type. There is also some low plumbing that makes it possible to have the cache stored to other locations, like files or SQL.

Thoughts: WHAT THE HELL PEOPLE!? Don’t you people use caching?! I don’t get this at all, not even slightly. If you have an idea why this is so unknown, please share with me in the comment.

More detail: http://www.sadev.co.za/content/net-baby-steps-part-vii-caching

CLR/BCL: GUID Parsing Improvements

imagePPDK: 77%

Introduction: This is a way to parse a string in and have it converted to a GUID, regardless of the format of the GUID.

Thoughts: I just don’t think people need to do parsing of GUID’s that much and so it isn’t needed that much.

More detail: http://msdn.microsoft.com/en-us/library/system.guid.parse.aspx