Threading Problem

Posted on 2009-04-22
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

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

    Accepted Solution

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

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    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.
    Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.

    755 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

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now