Link to home
Start Free TrialLog in
Avatar of thew00d
thew00dFlag for United Kingdom of Great Britain and Northern Ireland

asked on

When is multi-threading not multi-threading

I have a VB.NET console application that uses a System.Timers.Timer and monitors a folder using a System.IO.FileSystemWatcher.  The timer works fine but stops after having run 25 times or 50 on a multi processor server.  This suggests to me that it is hitting the maximum number of threads and then giving up.  I'm don't really know anything about multi-threading applications and haven't coded this as multi-threaded but I do use System.Threading.Thread.Sleep to get the app to pause in several places.

I have also tried swapping the timer to use the System.Threading.Timer but I get the same issue of it stopping after 25 goes.

Anyone out there that can help me sort out me timers?

Thanks, Stu
Avatar of RikeR
RikeR

Hi,

If you have not programmed your application to use several threads, it's not multithreaded.

The System.Threading.Thread.CurrentThread.Sleep() Blocks the current thread for the specified number of milliseconds. Since your application exists of at least 1 thread this is your main thread which is being suspended.

What this timer doind anyway
Avatar of thew00d

ASKER

I realise it would be quite difficult to "accidently" code something multi-threaded :-)

As for the timer, it checks for Zetafax status messages and runs a couple of stored procedures - nothing really

Is there a way to increase or decrease the maximum number of threads per processor - this would then confirm that it is in fact this limit it is hitting for some reason.

What else might cause it to stop firing after 25 runs?
This might sound a little anoying, but you're sure it not you who is disabling the timer?
Avatar of thew00d

ASKER

I am definately not disabling the timer - Its absolutely valid to ask - I've checked the code and rechecked for anywhere I may accidently be doing that.  That wouldnt explain why it stops after 25 times on my PC and 50 times on a multi-processor PC though...............
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of thew00d

ASKER



That appears to have worked. Tried it on my PC and it happily went past 25 Timer fires.  During each Timer event I had been Disabling and Re-enabling the timer rather than using Stop and Start.  Once I've tried the changes on the server I will get back.  Thanks to Idle_Mind and RikeR for the comments so far.  This problem has been annoying me for months and I've only just had time to try to sort it out.
Avatar of thew00d

ASKER

Spot on.  Nice one.