Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / March 2008

Tip: Looking for answers? Try searching our database.

How can I exit a method prematurely

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Roger - 28 Mar 2008 20:29 GMT
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
zacks@construction-imaging.com - 28 Mar 2008 20:53 GMT
> Hi,
>
[quoted text clipped - 10 lines]
>
> Roger

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

return;
Roger - 28 Mar 2008 21:25 GMT
On Mar 28, 3:53 pm, za...@construction-imaging.com wrote:

> > Hi,
>
[quoted text clipped - 14 lines]
>
> 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.
Roger - 28 Mar 2008 22:04 GMT
> On Mar 28, 3:53 pm, za...@construction-imaging.com wrote:
>
[quoted text clipped - 21 lines]
> 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.
rossum - 28 Mar 2008 22:07 GMT
>Hi,
>
[quoted text clipped - 10 lines]
>
>Roger
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
Lasse Vågsæther Karlsen - 29 Mar 2008 12:59 GMT
>> Hi,
>>
[quoted text clipped - 19 lines]
>
> 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.

Signature

Lasse Vågsæther Karlsen
mailto:lasse@vkarlsen.no
http://presentationmode.blogspot.com/
PGP KeyID: 0xBCDEA2E3

rossum - 29 Mar 2008 13:31 GMT
>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.
Agreed.  Normally I would send a "Please die now" message to the
thread I wanted to kill.

rossum
Howard Swope - 29 Mar 2008 23:29 GMT
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.");

                    }

             }

      }

}



> Hi,
>
[quoted text clipped - 10 lines]
>
> Roger

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.