thread question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Analizer1

    #1

    thread question

    c#2, vs2005
    hello
    i have say 5 threads running
    there running a instance of the same class
    so there is 5 executetasks

    sample example
    //this is a method of 1 thread there are 5 of these running in there own
    thread
    public void executetask()
    {
    while (_ServiceRunnin g)
    {
    try
    {
    if (oProcess.WorkT oDo())
    {
    oprocess.Execut e() ; // goes into process does its job no
    loops and returns, oProcess has its own error handler, therefor it will do
    clean up and return here
    }
    else
    {
    thread.Sleep(Ap pConfig.SleepSe conds*1000);
    }
    }
    catch(Execeptio n ex)
    {
    //this loop is the top most loop..so any errors at this level are
    fatal errors ie sql connection...so mthing else went wrong, disk io, etc
    // instead of this catch block i would like to to have a predefined
    event that calls a method to handle the service ...for instance
    //if the error is a sql connection error
    // dont stop service try to re-connect 3 times and if not stop the
    service
    // any examples of how to trigger a event to call a method is very
    helpful
    }
    }
    }

    thanks


  • Jon Skeet [C# MVP]

    #2
    Re: thread question

    Analizer1 <vettes_n_jets@ yahoo.comwrote:
    c#2, vs2005
    hello
    i have say 5 threads running
    there running a instance of the same class
    so there is 5 executetasks
    <snip>

    I don't see that this is really a threading question - it's just a
    question of how to raise an event from within a method (in particular,
    from within your catch block).

    See http://pobox.com/~skeet/csharp/events.html for lots of details on
    events.

    --
    Jon Skeet - <skeet@pobox.co m>
    http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
    World class .NET training in the UK: http://iterativetraining.co.uk

    Comment

    Working...