MS.COM Operations Tools Team WebLog

Hey - What does this button do?

C++ to C# Conversion Happiness

Hi.  This is my first ever web log post, so please be understanding while reading it. :-)

 

I recently converted a block of test scheduling code from C++ to C# and decided to choose a new design paradyme.  I was quite pleased with the results. 

The C++ code used a list of tests that was unordered and a dynamic pool of threads that consumed the tests to execute them.  There was a large amount of code to handle the thread synchronization, the dynamically growing thread pool and support for generic test execution.

The new C# code used two collections of tests and takes advantage of the built in thread pool in the .Net Framework.  The basic functionality is:

  1. Tests get added to the "pending" collection, which sorts them as they are added, by the time they are due to execute. 
  2. A timer is set to go off when the next test is due.
  3. When the timer expires the tests that are due are moved to an "executing" collection, which spins up a worker thread for each test, and a timer to track the test in case it times out.
  4. When a test completes, its results are stored in a "result" collection and the test is moved back to the "pending" collection.

The whole process it self perpetuating and this design really simplifies the code and makes it much more maintainable.  I was also amazed at how much smaller the resulting C# code was compared to the C++ original.  I'm sure the .Net Framework is largely responsible, but from a developer's standpoint, I'm still very pleased. 

 

Howitzer

Published Tuesday, September 07, 2004 3:26 PM by mscomts

Comments

 

AndrewSeven said:

paradigm ;)
September 7, 2004 4:31 PM
 

denise said:

I think that's the Canadian spelling for paradigm. :)
September 8, 2004 8:04 AM
 

Anonymous said:

Oops! Actually the Canadian spelling would be paradigmEh.
September 8, 2004 10:16 AM
 

Jeremy C. Wright said:

Nope. It's paradigm here as well. Now, when you only have 2 pennies to rub together... No, that's still not a pair-a-dimes.
September 8, 2004 10:46 AM
New Comments to this post are disabled

This Blog

Syndication

Tags

No tags have been created or used yet.

News

All opinions posted here are those of the author(s) and are in no way intended to represent the opinions of our employer. This is provided "AS IS" with no warranties, and confers no rights. Use of included code samples are subject to the terms specified in the Terms of Use.

© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Microsoft
Page view tracker