Tuesday, August 26, 2008

Try to post source code in an elegant manner

Elegance source code via http://formatmysourcecode.blogspot.com/ :

private void HeavyBackgroundWork()
{
Debug.WriteLine("Background thread: " + Thread.CurrentThread.ManagedThreadId);

// To simulate a time-cost work.
Thread.Sleep(1000);

synchronizationContext.Post(new SendOrPostCallback(delegate(object param)
{
// We have to access TextInfo by synchronizationContext, otherwise
// you will meet an exception.
TextInfo.Text = "HeavyBackgroundWork() has been finished.";
}),
null);

Debug.WriteLine("HeavyBackgroundWork finished.");
}


Another code formatter: http://www.manoli.net/csharpformat/.
But it seems that it's not friendly with blogspot.

No comments: