Solved

deadlocked threads

Posted on 2011-03-14
6
337 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
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

Technology Partners: 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!

Question has a verified solution.

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

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…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

628 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