Solved

deadlocked threads

Posted on 2011-03-14
6
335 Views
Last Modified: 2012-05-11
hi -- i think i have a deadlock going on with a thread that seems to hang (threadstate = stopped if i add some code to query its threadstate). is there a tool  or technique in visual studio 10 that allows me to examine specific threads and see where they may be stopped?
ultimately, i'm trying to figure why the thread is stopped and what it takes to get it restarted. thread.start() throws and error that says it is already running.
i'm using .net 4 and c#
0
Comment
Question by:jdcoburn
  • 3
  • 3
6 Comments
 
LVL 10

Expert Comment

by:Nash2334
ID: 35130138
If you are creating a multithreaded application use BackgroundWorkers - they can report progress.
0
 
LVL 10

Expert Comment

by:Nash2334
ID: 35130154
0
 

Author Comment

by:jdcoburn
ID: 35132967
i've structured my existing "worker" thread to run continuously (using a while loop). is there any issue with that? i noticed that the assumption seems to be that you start the background worker thread and it runs to completion and exits.
0
How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

 
LVL 10

Accepted Solution

by:
Nash2334 earned 500 total points
ID: 35133027
I'd say that's the case with most worker threads.  If you had something that required continuous processing I'd recommend going with a regularly scheduled service instead that ran at Timer intervals.  While loops are fine in multi-threaded apps but there really should be some terminal condition in your design.

In most Windows services I've written I'll create a Windows service and fire off a BackgroundWorker to complete the heavy lifting, while logging events in the calling thread.  When the worker is done, the service goes back to sitting silently until the timer ticks again.
0
 

Author Comment

by:jdcoburn
ID: 35133296
ok -- the reason i put the activity in a separate thread originally was that there are i/o calls out the usb port that have an indeterminate completion time. i believe a timer runs in a seperate thread, so i assume your approach will work. but all the stuff i've read on threads prior to this, and the various apps i've written, all seem to treat threads as having the same life as the application. they said, in effect, if you want to complete a thread, then create a condition for the while loop. starting and stopping the loop is done with the while loop condition. Aborting a loop is a bad thing.
am i missing something here?
0
 

Author Closing Comment

by:jdcoburn
ID: 35134590
i replaced the existing thread with the worker thread and i can cancel and restart the thread, which is what i wanted.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question