Event preemption?

So I’ve been having this wierd problem with event execution order where half way through handling one event another event handler is fired. If you know why please enlighten me!

Here’s a copy of my newsgroup post which you can find here.

I am seeing some unexpected behaviour in a single threaded winforms app

and was hoping someone could explain what is going on.

I have two events attached to a chart control on my form, and during

execution one event seems to preempt the execution of the other.

My code looks similar to the following:

private void MyChart_Click(object sender, System.EventArgs e)

{

…do some logic tests

GetSomeData();

}

// This event is attached to the context menu for the chart control.

private void DrillDownMenuItem_Click(object sender, System.EventArgs e)

{

…do stuff

}

private DataSet GetSomeData()

{

…setup tasks

…Call web service

…finish stuff

}

What happens is that when I right click and select drill down from the

chart controls context menu the MyChart_Click event fires and does the

logic tests. Execution then steps into the GetSomeData method, but when

the web service is called execution jumps to the

DrillDownMenuItem_Click event. This runs to completion then execution

returns to the GetSomeData method which finishes and finally returns to

the MyChart_Click event handler.

Can someone explain why this is so?

[EDIT] so I figured it out by myself. I turns out it is a bug in the dundas chart control >:-(

Code to HTML

So a while ago I found out about this VS.NET tool for converting code to HTML on Scott Galloway’s Blog.

At home I do all my development on a linux machine, and hence don’t use VS.NET. However the other night I found out about a neat little feature of Kwrite (text editor in KDE) that does essentially the same as the aforementioned tool. There is a “File->Export->HTML” option in Kwrite that will take all your nicely formatted and colourised code and produce an html version of it… fantastic!

Expect to see nicely formatted code snippets on my blog from now on =)

Refactoring hell

Arrgggh! I am stuck in refactoring hell with the data access layer code generator addin for visual studio I wrote.

Isn’t it funny how sometimes you think “I can make this so much better if I just change that…” and you end up in a world of pain :-/

Maybe listening to some smashing pumpkins will make it better…

Life on the bleeding edge…

It’s never easy thats for sure. I made the fateful decision the other day to upgrade my Mono installation. Why you say? Well I was seduced by the new language features, partial types, etc so I took the plunge and checked out the latest version from SVN.

Well, that went ok (surprisingly) and I now have Mono-1.1.2.99 installed on my machine. Unfortunately when I started Monodevelop things started to go distinctly astray :-/

I checked the latest version of Monodevelop out from SVN and after quite a few headaches (upgrading to gtk-sharp-2.0, trying to persuade gecko-sharp to compile against gtk-sharp-2.0… the list goes on!) I managed to get it to build, install and run!

Of course as soon as I opened a c# file it crashed… sigh.

Date comparison with Null is super slow!

I was recently performance testing a logging component I’d written which simply logs entries to text file when I stumbled on a performance bottle neck I’d never come accross before.

I wrote the following simple test:

System.Diagnostics.Debug.WriteLine(“Starting 10000 logs entries at: ” + DateTime.Now.TimeOfDay.ToString());


for(int i = 0; i < 10000; i++)

Logger.Instance.CreateLogEntry(“New entry number ” + i.ToString());

System.Diagnostics.Debug.WriteLine(“Finished writing entries at: ” + DateTime.Now.TimeOfDay.ToString());

This managed 10,000 writes in 0.5 secs. I then added the following line into the CreateLogEntry method:

if (_logDate.Date != DateTime.Now.Date)

I was using this check to see if the date had rolled over to the next day (This component is used by a windows serivce that runs continuously and creates a new log file each day). When I re-ran my test imagine my horror to see that the 10,000 writes was now taking 5 mins and 19 secs!

For a moment I wondered how date comparisons in .NET could possible be so slow, and it was then that I realised I was never initialising _logDate, so each time the CreateLogEntry method was called I was doing a comparison between DateTime.Now.Date and null. After fixing my mistake I was back to doing 10,000 writes in 0.53 secs… much better!

It did teach me an important leason though. Comparison with null is very expensive and should be avoided at all costs if performance is a priority.

Mono is cool!

I recently built myself a new computer, and this thing is a beast. AMD Athlon64 3400+, 1Gb RAM, a bit over half a terabyte of SATA disk, Nvidia FX5900 with 128Mb VRAM, and other assorted goodies 😉

I am runnng 64 bit Gentoo on this machine, and it is blisteringly quick!

So over the last week or so I finally got some time to get Mono running. It was a bit of a challenge as the 64bit port of mono is fairly fresh (read need to get from CVS). I have however managed to get it build and installed and was able to test it by building a simple little hello world type console app.

The cool thing about using the 1.1.1 version from CVS is that it includes gcms, which is the new mono compiler for generics. So, I have had a quick play with generics with mono and I like!

So if you have a .NET runtime, what is the next thing your going to want? Yep, an IDE. I checked out a plugin for eclipse (which I use for my C/C++ coding) however all it really gave you was syntax formating. Coming from VS.NET I am a little spoiled and I really wanted tab completion. So I looked into monodevelop. Getting monodevelop to compile took a few goes getting the dependancies etc satisfied, however a day or so ago I managed to get it running and bliss! I now have code completion for 64 bit .NET (with generics support) all on my linux machine.

I am a happy camper.

DataSets – the fog clears

Well, I’ve been using datasets since I started using .NET about 3.5 years ago, but in the past few days I’ve learnt a few new things that I thought I’d share with you.

Datasets are not stored internally as xml. I guess I had always assumed that they were, probably for a couple of reasons. One; I think someone told me this early in my .NET experience; and Two, datasets handle xml so well it almost seems like a logical conclusion. Suffice it to say, I was wrong, and you can find out all the details here.

Another point of dataset enlightenment I had is this:

Databinder.Eval is bad! Apparently ( and I must admit I haven’t written any tests to prove this, although it does make sense ) using Databinder.Eval is about 20% slower than using explicit casting. This is because Databinder.Eval uses reflection to figure out what the type of the object in the container is that you are trying to display. So instead of doing something like this:

<%# Databinder.Eval(Container.DataItem, “MyItem”) %>

you should do something like this:

<%# ((DataRowView)Container.DataItem)[“MyItem”] %>

however if you do this, you will also need to add this line

<%@ Import Namespace=”System.Data”%>

to the top of your html page , otherwise you will get the following error at runtime:

Compiler Error Message: CS0246: The type or namespace name ‘DataRowView’ could not be found (are you missing a using directive or an assembly reference?

You can find out more about this here.

First Post to my new blog!

Well, I thought it was about time I got my act togeather and got a blog going. I know I am a bit late jumping on this particular bandwagon, however I have just recently started reading a lot of other peoples blogs (particularly .NET related stuff ) and am find the experience very rewarding. I especially like the ability to syndicate content from blogs using RSS and have it all on my desktop in one nice easy to find location.

Anyways, this will be a place for me to write my random thoughts, and post any .NET tidbits I come across or dream up.

I guess a link back to my website is probably in order as well 😉