473,327 Members | 2,069 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

2003 / XP multi-threaded problems

Hi,

I have a multi-threaded application (have also tried as service - same
behaviour) that runs fine on XP, but not on 2003. Symptoms are:

Threads are started normally, locks acquired and released as needed,
runs fine for some time, then stops - Visual Studio detects no
exceptions, and I have placed break points on all the handling code to
catch them. No errors / failures are logged, but child threads have all
exited, and I am left with a single thread of the application or service
instance. There are no event log entries either. The error happens
regardless of whether the debugger is attached.

I have spent a lot of time debugging this and I'm running out of
thoughts. The test server (2003) is fully patched to the same point as
my XP development machine.

The application / service is completely in managed vb.net code.

Any help would be greatly appreciated

Rob
Nov 3 '05 #1
5 1676
Found out some more information...

The test machine is slower (considerably) than the development machine
and it not multi-threaded. When I try and start too many threads, the
application gets to a point where it just ditches the threads with out
seeming to raise an error ...

e.g.

thread 1 starts instances of thread 2 each time it needs to write to a
database. thread 2 for some reason is delayed in it's completion (for
example if connection to db is broken) - this causes threads to stack
up. When thread 1 has reached a critical mass, it just dumps all
instances of thread 2 and sits there pretending nothing happened. The
work done on thread2 is critical to the application, so I don't want to
just timeout on the thread.

Can anyone tell me if the threads raise an event of some kind and if so
how should I catch it (no exceptions are thrown)

Thanks

Rob

Rob Durant wrote:
Hi,

I have a multi-threaded application (have also tried as service - same
behaviour) that runs fine on XP, but not on 2003. Symptoms are:

Threads are started normally, locks acquired and released as needed,
runs fine for some time, then stops - Visual Studio detects no
exceptions, and I have placed break points on all the handling code to
catch them. No errors / failures are logged, but child threads have all
exited, and I am left with a single thread of the application or service
instance. There are no event log entries either. The error happens
regardless of whether the debugger is attached.

I have spent a lot of time debugging this and I'm running out of
thoughts. The test server (2003) is fully patched to the same point as
my XP development machine.

The application / service is completely in managed vb.net code.

Any help would be greatly appreciated

Rob

Nov 3 '05 #2
Rob,

"Rob Durant" wrote:
Found out some more information...

The test machine is slower (considerably) than the development machine
and it not multi-threaded. When I try and start too many threads, the
application gets to a point where it just ditches the threads with out
seeming to raise an error ...

e.g.

thread 1 starts instances of thread 2 each time it needs to write to a
database. thread 2 for some reason is delayed in it's completion (for
example if connection to db is broken) - this causes threads to stack
up. When thread 1 has reached a critical mass, it just dumps all
instances of thread 2 and sits there pretending nothing happened. The
work done on thread2 is critical to the application, so I don't want to
just timeout on the thread.

Can anyone tell me if the threads raise an event of some kind and if so
how should I catch it (no exceptions are thrown)


I think you either have a deadlock issue, or you spawn too much threads. It
is typical that when software is put on a faster/slower machine, or a machine
with fewer/more CPU's, it exposes multi-threading problems that were already
there but didn't trigger. Another thing I'd advise against, is having threads
with different priorities; this could induce dirty deadlocks (ie hard to
find).

I don't understand you when you say 'threads stack up'. What do you mean
here, that they just wait for db actions to complete? That is a regular
waiting operation and I don't see how that could lock it up completely (a
Thread.Interrupt should be able to unblock it).

What do you mean when you say 'thread 1 reaches critical mass'??? What do
you mean by 'all instances of thread 2'. You mean you have a specific
function executed in several threads?

Kind regards,
--
Tom Tempelaere.

Nov 3 '05 #3
> Can anyone tell me if the threads raise an event of some kind and if so
how should I catch it (no exceptions are thrown)


There has been a lot of discussion about threading and exceptions in these
newsgroups. You might try searching for some interesting reading, although I
guess you have already tried that.

Contrary to what I have read, in a multi-threaded windows form app, I think
you need to enable exception handlers for both UnhandledException and
ThreadException. For testing my app, I arrange for an exception to be thrown
in the gui thread or in a new worker thread. When I run in the .net ide with
out of the box exception settings, the gui thread exception is trapped by my
handler, but the worker thread exception is not, but it is trapped in the
ide. When I run outside the ide, both are trapped. The gui thread throws
ThreadException, and the worker thread throws UnhandledException.

Not so intuitive, in my opinion - the choice of names is peculiar, and why
does the ide step in front if my handler? So, what to do? Enable both in
your sub main, and arrange for both to report out info if they are called,
and be suspicious of different behavior in the ide vs standalone.

Nov 3 '05 #4
AMercer wrote:
Can anyone tell me if the threads raise an event of some kind and if so
how should I catch it (no exceptions are thrown)


There has been a lot of discussion about threading and exceptions in these
newsgroups. You might try searching for some interesting reading, although I
guess you have already tried that.

Contrary to what I have read, in a multi-threaded windows form app, I think
you need to enable exception handlers for both UnhandledException and
ThreadException. For testing my app, I arrange for an exception to be thrown
in the gui thread or in a new worker thread. When I run in the .net ide with
out of the box exception settings, the gui thread exception is trapped by my
handler, but the worker thread exception is not, but it is trapped in the
ide. When I run outside the ide, both are trapped. The gui thread throws
ThreadException, and the worker thread throws UnhandledException.

Not so intuitive, in my opinion - the choice of names is peculiar, and why
does the ide step in front if my handler? So, what to do? Enable both in
your sub main, and arrange for both to report out info if they are called,
and be suspicious of different behavior in the ide vs standalone.


Thanks for this advice. I have spent another day checking the code and
playing around with it.

By critical mass I meant a defined limit that seemed to be more than the
computer could cope with (although CPU usage was around 4-5% at the time!?!)

I have a manager that spawns 'main jobs', (perhaps 1 to 3 at a time)
which spawn 'sub-jobs' themselves... only 10 instances of the 'sub-jobs'
are allowed at any one time, and I am testing with only one 'main job'
running.

I think I may be closer to the answer...

The main worker thread starts by initialising and starting a timer. It
then uses each elapses event to do some work and set the 'sub job'
going, but by the time an elapsed event occurs on the timer. Once the
work is done, it will use the elapsed event to stop the timer and exit.
But the thread seems to be exiting as soon as the initialisation
function has completed.

So another question...

Is it right to expect that because a timer is running, the thread should
stay alive? or should a thread exit when the function exits despite the
thread still performing work? I would have expected the thread to stay
alive for as long as the timer is running. If the first is true, how
should I keep the function alive at the same time as handling the timer
ticks?

Rob
Nov 4 '05 #5
> Is it right to expect that because a timer is running, the thread should
stay alive? or should a thread exit when the function exits despite the
thread still performing work?


Ultimately, a thread starts with a call to a sub/function. When that
sub/function exits/returns, the thread is over. Period. It sounds to me
like this is the source of your problem.

What you need to do in general terms is as follows. According to some rules
of your choosing, you launch worker threads. The rules can include whatever
you want. Maybe you want only a couple running at a time. Maybe some depend
on outputs of others. The specifics of that are up to you. But the app's
main thread should be responsible for launching the workers. A timer for the
main thread is likely to be useful to you.

The worker threads should do their work to completion and then quit. As
they produce output, they should make the data available to the main thread.
Here, thread contention issues need to be solved. What I use is a queue -
threads thread-safely append outputs to a queue. The main thread can
periodically sample the queue (alternatives to polling are also possible).

One thing to worry about is launching too many or not enough threads. Say
you want to retrieve 100 urls from the web. You could launch 100 threads,
each responsible for one url. You could launch one thread responsible for
all 100. Or 10 threads each responsible for 10 urls. 100 threads is bad
because it is resource unfriendly. 1 thread is bad because one slow web
server stops the entire download process, ie it is really single threaded.
10 threads is good because it is not too resource unfriendly and you get all
the benefits of multi-threading.

This is fairly easy to arrange in a standard windows form app which has a
message pump and all that entails. Your main thread is the gui thread, and
it is awakened by events, and you can arrange for your worker threads to do
things that cause the gui thread to respond to an event. So, as time passes
and conditions change, your main thread can launch workers, and as the
workers finish their jobs, the main thread sees and responds to their outputs.

I have no in depth experience with services, console apps, and other
settings, so I don't want to make the same 'fairly easy' assertion. But my
guess is that this same general approach should work in these settings.

Nov 4 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Corrie Meyer | last post by:
Announcement: SwiftReports standard edition 1.0 for Visual Studio ..NET 2003 released by UniSwift. We are pleased to announce the first release of a fully-managed reporting tool for the...
1
by: Prasad Patil | last post by:
Hi, I have installed Office 2000 & Office 2003 on my Machine I wish to use excel 2003 in my Dot Net Project When I reference the Microsoft Excel 5.0 Object library the code using Excel...
15
by: Jeff Keller | last post by:
I've built all of my apps in Access 97, but I think it's time I moved to some newer technology (a little late to the web app game...) so I'm considering an upgrade. Any reason not to go straight...
3
by: Terry Block | last post by:
We have an Access 97 database app that we'd like to enable (not convert) for Access 2003. We still have users running 97 and are not prepared to upgrade everyone who uses this database to the 2003...
1
by: Mike | last post by:
Hi Hi We are currently upgrading from access 97 to office 2003 on site. We would like to upgrade our access databases to Access 2003 but we wish to remove Microsoft access software from our end...
2
by: lambej12 | last post by:
I am a relatively new user. My position is to maintain an Access DB that is running in a multi user enviornment and split on a network running Front(2K and 97) and BE(97). The DB has been used...
0
by: google | last post by:
Hi, after fighting with an issue in Visual Studio.NET 2003 in aspx, I've finally figured out what it is and maybe you might find it usefull. Symptoms: When you try to open a .aspx or...
52
by: Neil | last post by:
We are running an Access 2000 MDB with a SQL 7 back end. Our network guy is upgrading to Windows Server 2003 and wants to upgrade Office and SQL Server at the same time. We're moving to SQL Server...
1
by: KrazyKasper | last post by:
Access 2003 – Multi-Column List Box – Select Multiple Items I have a multi-column (3 columns) list box that works well to select one set of records or all sets of records (based on the first field...
0
by: TLarge | last post by:
I wish to install an access 2003 in a multi user enviroment. My client does not wish to install Access on his machines as he is running open office. I am familiar with spliting data bases and also...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.