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

x
?
Solved

Threading Problem

Posted on 2009-04-22
3
Medium Priority
?
197 Views
Last Modified: 2013-11-08
Hello,

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.

Thanks!
Thread oThread = new Thread(new ThreadStart(snapThread.ProcessThread));
oThread.Start();
 
//Code
 
oThread.Join(180000);
oThread.Abort();
 
 
snapThread.ProcessThread()
{
        System.Diagnostics.Process.Start();
         if (pStart.WaitForExit(130000) == false)
          {
               pStart.Kill();
          }
}

Open in new window

0
Comment
Question by:grogo21
3 Comments
 

Author Comment

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

Accepted Solution

by:
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)){
  oThread.Abort();
}

Open in new window

0
 
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
0

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