Solved

deadlocked threads

Posted on 2011-03-14
6
332 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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

708 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now