Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

deadlocked threads

Posted on 2011-03-14
6
Medium Priority
?
340 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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
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

Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
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…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

971 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