Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

PetriDish: Multi-threading for performance in C#

, 28 May 2008
An investigation into advanced concurrent programming.
petridish_bin.zip
petridish_src.zip
PetriDish
PetriDish
Common
Images
key.png
Properties
Settings.settings
System.Threading.dll
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PetriDish
{
	static class Extensions
	{
		public static string ToNormalDisplay( this DateTime dt )
		{
			return dt.ToString( "yyyy-MM-dd HH:mm:ss" );
		}

		public static string ToNormalInternal( this DateTime dt )
		{
			return dt.ToString( "yyyy-MM-dd'T'HH:mm:ss" );
		}

#if WinForms

		public static string ToPathEllipsis( this string s, int width )
		{
			//string s = @"C:\Program Files\Directory\Subdirectory\filename.extension";
			string copy = String.Copy( s );

			TextRenderer.MeasureText( copy, System.Drawing.SystemFonts.DefaultFont, new Size( width, 0 ),
				TextFormatFlags.ModifyString | TextFormatFlags.PathEllipsis );

			int i = copy.IndexOf( '\0' );
			string r = ( i < 0 ? s : copy.Substring( 0, i ) );
		}

#endif

		public static T Modal<T>( this IEnumerable<T> list )
		{
			int count = list.Count();
			if ( count == 0 ) return default( T );

			var sorted = list.OrderBy( o => o );

			return sorted.ElementAt( count / 2 );
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Nicholas Butler

United Kingdom United Kingdom

I built my first computer, a Sinclair ZX80, on my 11th birthday in 1980.
In 1992, I completed my Computer Science degree and built my first PC.
I discovered C# and .NET 1.0 Beta 1 in late 2000 and loved them immediately.
I have been writing concurrent software professionally, using multi-processor machines, since 1995.
 
In real life, I have spent 3 years travelling abroad,
I have held a UK Private Pilots Licence for 20 years,
and I am a PADI Divemaster.
 
I now live near idyllic Bournemouth in England.
 
If you would like help with multithreading, please contact me via my website:
 
 
I can work 'virtually' anywhere!

| Advertise | Privacy | Mobile
Web01 | 2.8.140827.1 | Last Updated 28 May 2008
Article Copyright 2008 by Nicholas Butler
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid