How can I exit a method prematurely

R

Roger

Hi,

I've implemented a windows service that calls an SSIS package. Every
so often, the SSIS package does not return control to the calling
method. What I've implemented is a sentinel thread that is spawned
before the execute method of the SSIS package which will email me if
execution occurs for a prolonged period. What I want to know is, how
can I implement a solution that will force the SSIS object to timeout
and return control to the calling method in the event handler of the
sentinel thread? Code samples would be appreciated.

Thanks,

Roger
 
Z

zacks

Hi,

I've implemented a windows service that calls an SSIS package.  Every
so often, the SSIS package does not return control to the calling
method.  What I've implemented is a sentinel thread that is spawned
before the execute method of the SSIS package which will email me if
execution occurs for a prolonged period.  What I want to know is, how
can I implement a solution that will force the SSIS object to timeout
and return control to the calling method in the event handler of the
sentinel thread?  Code samples would be appreciated.

Thanks,

Roger

To exit out of a method before it has completed, just do a:

return;
 
R

Roger

To exit out of a method before it has completed, just do a:

return;

The problem is, the SSIS object retains control due to a deadlocking
issue and doesn't give me the opportunity to return. I need another
method of raising exception from method without stopping the service
outright.
 
R

Roger

The problem is, the SSIS object retains control due to a deadlocking
issue and doesn't give me the opportunity to return. I need another
method of raising exception from method without stopping the service
outright.

Nevermind. I figured out that I can run through all the running SSIS
packages and shutdown the offending packages.
 
L

Lasse Vågsæther Karlsen

rossum said:
Call SSIS in a worker thread. Spawn your sentinel thread. If the
Sentinel thread finishes before the SSIS thread then kill the SSIS
thread from you main thread.

If you are not actually doing anything in your main thread then you
might be able to replace the sentinel thread with a simple timer in
the main thread.

rossum

Do not kill another thread forcibly. You need to figure out a way to
talk to the other thread and have it exit by its own.

Killing a thread is doable if your program is to be closed down, but
other than that, it's a big no-no.
 
H

Howard Swope

I often do something like this:

using System;

using System.Threading;



namespace CSConsole

{

class Program

{

static void Main()

{

Console.WriteLine("Monitor thread starting worker thread.");



Thread thread = new Thread(ThreadProc);

thread.Start();





Console.WriteLine("Monitor thread watching worker for time out.");

if (!thread.Join(5000))

{

Console.WriteLine("Monitor thread determines worker has timed out and calls abort.");

thread.Abort(); // thread timed out

}



Console.WriteLine("Monitor thread waits until worker thread is cleaned up.");

// wait until thread is done

thread.Join(-1);



Console.WriteLine("Monitor thread done. Press a key to quit.");

Console.ReadLine();

}



static void ThreadProc()

{

try

{

Console.WriteLine("Worker thread is doing work.");

// my bad thread is locked up

while (true)

{

Thread.Sleep(0);

}

}

catch (ThreadAbortException)

{

Console.WriteLine("Worker thread received abort signal.");

}

finally

{

Console.WriteLine("Worker thread cleaning up.");

}

}

}

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top