[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 219
  • Last Modified:

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
0
thew00d
Asked:
thew00d
  • 4
  • 2
1 Solution
 
RikeRCommented:
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
0
 
thew00dAuthor Commented:
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?
0
 
RikeRCommented:
This might sound a little anoying, but you're sure it not you who is disabling the timer?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
thew00dAuthor Commented:
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...............
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
How often is your timer firing?  One possibility is that you are getting reentrant code in your timer.  What you can do is turn off the timer when it fires, do something and then turn it back on:

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Timer1.Stop()

        ' do something in here...

        Timer1.Start()
    End Sub

Without further detail into how your app works or seeing more code we can only make vauge guesses though...
0
 
thew00dAuthor Commented:


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.
0
 
thew00dAuthor Commented:
Spot on.  Nice one.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now