Process started by Process.start() returns incorrect process ID?

An example of how I did it: bool started = false; var p = new Process(); p.StartInfo.FileName = “notepad.exe”; started = p.Start(); try { var procId = p.Id; Console.WriteLine(“ID: ” + procId); } catch(InvalidOperationException) { started = false; } catch(Exception ex) { started = false; } Otherwise, try using handles like this: Using handlers Getting … Read more

Does the .Net Framework 4.0 Installer include the .Net Framework 3.5?

The .NET 4.0 installer doesn’t include the .NET framework 3.5. There is some information on this topic in MSDN: The .NET Framework 4 is highly compatible with applications that are built with earlier .NET Framework versions, except for some changes that were made to improve security, standards compliance, correctness, reliability, and performance. The .NET Framework … Read more

Unable to load SOS in WinDbg

The CLR runtime dll was renamed to clr.dll with .NET 4. So in order to load the correct version of SOS you need to adjust your .loadby command. I.e. .loadby sos clr Also, if you’re on 64 bit, you should install the 32 bit version of Debugging Tools for Windows as well in order to … Read more

How can I use the async keywords in a project targeting.net 4.0

You want the Microsoft.Bcl.Async package. That’s a properly released, non-CTP package that is stable. This also requires VS2012 since an updated compiler is needed to understand async and await. In theory one could use older tools from VS2010 along with the older CTP library, I’d strongly recommend that you don’t – it has bugs and … Read more

How to create custom scaffold templates in ASP.NET MVC5?

First, it looks like you have Visual Studio 2013 and 2012 both installed on your computer. I tried looking up the path you provided, I couldn’t find it. On your path it looks like you’re trying to use MVC4 templates. Here is my path: C:\Program Files (x86)\Microsoft Visual Studio 12.0\ Common7\IDE\Extensions\Microsoft\Web\Mvc\Scaffolding\Templates Below is how I … Read more

How to construct WMI query

Try this: string wmiQuery = string.Format(“SELECT CommandLine FROM Win32_Process WHERE Name LIKE ‘{0}%{1}'”, param1, param2); Adding some test info: string wmiQuery = string.Format ( “SELECT Name, ProcessID FROM Win32_Process WHERE Name LIKE ‘{0}%{1}'”, “wpf”, “.exe” ); Console.WriteLine ( “Query: {0}”, wmiQuery ); ManagementObjectSearcher searcher = new ManagementObjectSearcher ( wmiQuery ); ManagementObjectCollection retObjectCollection = searcher.Get ( … Read more

MSBUILDEMITSOLUTION not working with .NET 4?

Set MSBuildEmitSolution=1 and then build from the command line. You should then see a MySolution.sln.metaproj file near MySolution.sln. Notes: If you open a command prompt window, then set the env var via System Settings, you will have to open a new command prompt. You’d think you could also use msbuild /p:MSBuildEmitSolution=1, but you can’t.

Properly disposing of, and removing references to UserControls, to avoid memory leak

foreach (Control control in flowPanel.Controls) { if (control != NodeEditPanel.RootNodePanel) { control.Dispose(); } } flowPanel.Controls.Clear(); This is a pretty classic Winforms bug, many programmers have been bitten by it. Disposing a control also removes it from the parent’s Control collection. Most .NET collection classes trigger an InvalidOperationException when iterating them changes the collection but that … Read more