Tuesday, October 28, 2014

Processes, Threads, and Process Real-Time "fun"

Process: A single running program. The Process.Start method is what shows documents on a computer, goes to web pages, and executes EXE programs.. like Photoshop or Microsoft Word!

Thread: By default in .NET, the programs are single-threaded.

However, you have the ability to create multiple threads. The reason you would want to do this is because if you have only one thread, the user is going to have to wait until that thread is done running before they can do anything in the program.

Here's an example of an application and how it might use multi-threading:

There are commercial software packages for doing 3D rendering, like 3D Studio Max. This program would be a running Process. These create rendered CGI images and video, like what you see in a Pixar movie. The artist creates wireframes and then renders them.

If they were single-threaded, the artist would have to sit and not do anything while it is being rendered.

However, if the Process started a separate thread for rendering, the artist could still keep creating wireframes in the program, and the rendering thread would render whatever wireframe they said to render.

Within that Process, however, there could be multiple threads. A Process that's RealTime (top of the food chain) could have 2 threads running, one low priority and one high priority. Within that process, the high priority thread is going to take precedence over the low priority thread. According to MSDN the following are the possible priorities for (from highest to lowest priority):

  • Processes: RealTime, High, Above Normal, Normal, Below Normal, Idle
  • Threads: Highest, AboveNormal, Normal, BelowNormal, Lowest

Here is an example of the method to set these properties in your program using C#:

Process Priority + Thread Priority work together. If you set a Process Priority to RealTime, it means that program is going to take priority over EVERYTHING else, including OS-level stuff. If you have a quad-core (4 cores) with hyper-threading (each of your cores will run 2 processes, thus you show 8 cores when you check your windows processes).. putting a program on RealTime may not be a big deal. However, if you do not have a very fast computer with multiple cores I would be wary of running or testing a program set to RealTime because this can override basic functions such as your keyboard, mouse, and task manager. Therefore, you would be unable to use your computer or stop the program which can cause problems.

Sunday, October 19, 2014

.NET Unit Test Frameworks

Just a brief summary of some of the Unit Test Frameworks out there right now for C# and a basic summary of pros/cons of each.


  • Leanest and newest framework. It can be integrated into the IDE VS 2013 using http://www.testdriven.net/.
  • Unique, modern, and flexible approach to unit testing: very extensible, control over base methods (overrideable), fit-style testing directly out of the box,
  • Combines well with mocking framework, Moq for a very flexible, extensible, and powerful platform for implementing automated testing.
  • Very poor documentation.
  • Written by the original inventor of NUnit.


  • Most standard and the first one created of the three.
  • It can also be integrated into the IDE VS 2013 using http://www.testdriven.net/.
  • NUNit has TestCaseSource attribute which helps you to achieve parametrized test cases but in MSTest you'll need DataSoruce which would be in xml file and will be difficult to manage when you have complex logic in method.
  • NUnit is faster as compare to MSTest.
  • NUnit has since added most of the attributes that XUnit has, but does not quite have as much flexibility.


  • Only one with built in IDE integration and backed by Microsoft. The visual studio test-runner is slower than Testdriven.Net + NUnit or XUnit.
  • MSTest has no x64 support. Tests always run as x86.
  • Does not run standalone very well.
  • Strategy is targeted at many different styles of automated testing, including Integration Testing, System Testing, Performance Testing, but not specifically for unit testing, because it's too heavy to work with.