Help on Multithreading

  • Thread starter Thread starter MS Newsgroups
  • Start date Start date
M

MS Newsgroups

Hi,

I have an application that runs a timer and executes a method in a class as
a new thread every 60 seconds, the thread takes 65 seconds to execute so
there is a 5 second overlap when 2 threads are running.

The problem i have is that i am experiencing sudden high CPU utilization
that lasts for a couple of seconds, and i believe that i have managed to tie
this down to occuring when the thread is terminated.

If I in the end of the thread use

threading.thread.currentthread.abort
threading.thread.currentthread.join

as the documentation specifies is the correct way of terminating a thread, i
get a 3-4 second 100% CPU spike that my application can't live with

If I don't use any code at all in the end of the method or only specifies
threading.thread.currentthread.join, everything runs smooth for about 25
minutes and then no more threads are executed and if i monitor the .Net CLR
Locking & Threads-> # Current recogized threads i can see that this value
increases until it reaches 25 which i believe is the default maximum number
of threads the CLR accepts.

Question is:

What am i doing wrong ? Am i supposed to actively abort my threads and if so
why do i get this CPU spike ? Are there any other ways of ending a thread ?
Why is the number of threads increasing, is there a way to "reclaim" threads
that has finished

Appreciate all help on this

Regards

Niclas
 
Thanks Fergus,

I have some more info, and i am now not sure if this is a multithreading
issue any more....

When the thread runs out, i raise a event that the processing has completed
that has a handler in the originating for that does some processing. This
processing consists in sending a byte array to a server through a remoting
component.

If i comment out the sending of the byte array, the threads runs smoothly
and they seem to finish properly without any aborts and the number of
threads are not increasing.

The remoting component method works brilliant under all circumstances except
for when a thread aborts. If i set therad.sleep(thread.timeout.indefinately)
for examle everything works like a charm untill all connections has been
used up. I have also thried to sleep the thread for a couple of minutes to
make sure that all file processing is done (which takes less than a second)
before i allow the thread to terminate, but this only delays the high CPU
problem with the same time as i sleep the thread.

Are there any known issues with remoting and multithreading that you are
aware of ?

Thanks

for helping out

Niclas
 
Lol, Chris,

Spoke too soon, cos Nick came online and Multithreading in VB.NET
has to be the best chat room going.

Regards,
Fergus
 
Hi again Niclas,

I'm afraid I've not done any remoting.

Have you explored 2) and 3) and considered 4) from my previous
post?

For 4) I'd want something minimal that's quick to download and
will compile without needing too much, if any, of your app stuff. If
you do send it, use my email.

Another question, too:
You say that you raise an event which then does the remote call.
Which thread is that executed in ?

Awaiting your experimentation.

Regards
Fergus
 
Fergus,

I just found that my CPU spike was caused by a Do-While loop and not related
to multithreading. Guess i got mislead by all the fancy stuff and had the
solution staring at me all time.

Sorry for wasting your time on this

Thanks for trying to help

Regards

Niclas
 
Lol. No worries Niclas.

Blinded by the light,
I looked up,
I looked back.
Now everything's all right

Best wishes,
Fergus
 
Back
Top