[Last Call] Learn how to a build a cloud-first strategyRegister Now


Threading Problem

Posted on 2009-04-22
Medium Priority
Last Modified: 2013-11-08

below I have a basic structure for my code.  Please notice WaitForExit(130000).  After exactly 130 seconds the process is ended but it also stops my webservice.  Why is this happening?  There are no exceptions being raised.

Thread oThread = new Thread(new ThreadStart(snapThread.ProcessThread));
         if (pStart.WaitForExit(130000) == false)

Open in new window

Question by:grogo21

Author Comment

ID: 24212103
Actually, oThread.Abort(); could also be causing the service to stop running.  I'm not sure though
LVL 15

Accepted Solution

oobayly earned 1400 total points
ID: 24218041
By stopping, do you mean that the webservice stops for about 130s before returning a response?

Join has a simple function, it tells the calling thread to wait until the thread (in this case oThread) to finish. If it completes before the timeout given it returns true. If the timeout is reached before oThread completed, false is returned. This way you know whether you know whether you need to call Abort. Have a look at the example.

The code you have presented does the following:
Starts a thread that in turn starts a process. This thread will allow the process to run for 130s.
Immediately after oThread has been started, you tell the main thread to block for 180s or until oThread has completed, whichever is comes first.

Basically, you're telling oThread to run the process for 130s only, but blocking the application for 180s, so what's the benefit of putting the process in a separate thread?

// Abort oThread only if it's still running after 180s
if (!oThread.Join(180000)){

Open in new window

LVL 26

Assisted Solution

by:Anurag Thakur
Anurag Thakur earned 600 total points
ID: 24221597
the code that you have shared is not complete
some of the variables are being used but are not defined or their meaning not too clear

and please alos explain what you are trying to achieve so that we can help in a better way

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

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

High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
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. …

829 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