Search code examples
c#queueuserworkitem

C# multi CPU for ThreadPool.QueueUserWorkItem


I have a program that uses:

ThreadPool.QueueUserWorkItem(new WaitCallback(FireAttackProc), fireResult);

On Windows7 and Vista it works fine.

When I try to run it on XP the result is a bit different from the others.

I was just wondering in order to execute QueueUserWorkItem properly do I need a dual CPU system?

The XP I tried to test on had .Net 3.5 installed.

Inputs most welcome.

EDIT: The callback proc plays a series of sound files. in win7 and vista they all play. but in xp only a couple of them plays. I get no exceptions from the program.

EDIT: Yes the XP box is single core. more than 5 years old.

EDIT: My app uses Winsock and I ran both the client and server on the XP machine. I will try running it with a single instance per machine and see how it reacts.

EDIT: How are you playing the sounds?

            SoundPlayer fire = new SoundPlayer(Properties.Resources.fire);
            fire.PlaySync();
            fire.Dispose();

Solution

  • The main difference is that, on a single core system, only one thread can run at a time. If your program is designed properly, this shouldn't matter, as the operating system switches the threads in and out and manages this for you.

    If you're seeing a difference on a single core system, this most likely means you have a race condition in your code. The only difference should be that it takes longer - since the OS can't run both threads concurrently.