Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

deadlocked threads

Posted on 2011-03-14
6
Medium Priority
?
339 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
Containers & Docker to Create a Powerful Team

Containers are an incredibly powerful technology that can provide you and/or your engineering team with huge productivity gains. Using containers, you can deploy, back up, replicate, and move apps and their dependencies quickly and easily.

 
LVL 10

Accepted Solution

by:
Nash2334 earned 2000 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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

730 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