C#

C# Puzzle: What does this program do?

Consider the following code: class Woot { private static float PI; private static bool initialized = doInitialize(); private static bool doInitialize() { if (!initialized) { var thread = new Thread(() => { PI = 3.14f; }); thread.Start(); ...

Visual Studio 2010 bug: NullReferenceException when opening any file, caused by a docked add-in tool window

Here’s an issue I’ve been struggling with: it seems that by accessing a certain property of a docked tool window of an add-in, an exception is thrown somewhere inside Visual Studio 2010. It’s caught internally, and the exception message, “Object reference is not set to an instance of an object”, is shown whenever I was trying to open any file (code or otherwise). Here’s the offending code (this OnConnection method belongs to a C# Add-in code, it’s pre-generated when you create a new Add-in for Visual Studio): public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom){ _applicationObject = (DTE2)application;...

ReSharper 5.0 Hidden Gem – Patterns Catalogue

Have I mentioned that I love ReSharper? While patiently waiting for the 5.0 release to RTM, the team at JetBrains have shipped the Beta 2 release (build 1618). This is a very stable, very good improvement over the previous nightly builds. One of the things that improved the most with this release is the SSR – Structural Search and Replace. It’s a new feature, allowing you to specify code patterns to be added as hints, errors or warnings to the ReSharper code analysis, as well as specifying a replacement pattern. Here is an example of this feature, taken...

Awesome tip: make View Code default double click action on a WinForm control

Here is something I wish I'd known years ago - you can make the "View Source" action default when you double click on a WinForm control. Here's how: Right click any Form/UserControl file, and choose Open With… Select CSharp Editor, then press Set as Default ???? Profit! That's it! Now you won't break the keyboard when you accidentally double click on your MainForm.cs file.

«September»
SunMonTueWedThuFriSat
2930311234
567891011
12131415161718
19202122232425
262728293012
3456789