Problem with Thread.Abort()

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • raghudr@gmail.com

    Problem with Thread.Abort()

    Hi all,

    I am implemeting a splash screen in C#

    I got a useful link from here :-


    //Logic when to display a splash screen is:-

    Splash screen should start

    //Long process which may take 1-2 min depending on size of XML file
    which i am parsing

    Splash screen should end

    //end of logic

    So to start the splash screen:-

    i coded :-

    Thread th

    Startsplash()
    {
    th = new Thread(new ThreadStart(DoS plash));
    th.Priority = ThreadPriority. Lowest;
    th.Start();

    }

    private void DoSplash()
    {

    sp = new Splash();
    sp.ShowDialog() ;

    }

    //splash screen starts displaying

    //To end the splash screen i have coded:-

    public void StopSplash()
    {
    try
    {
    if (true == th.IsAlive)
    {

    if (sp != null)
    sp.Close();
    th.Abort();
    th.Join();

    }
    }
    catch (ThreadAbortExc eption abortException)
    {
    Thread.ResetAbo rt();

    //
    Console.WriteLi ne((string)abor tException.Exce ptionState);
    }

    Thread.Sleep(10 00);


    }

    Problem is when i restart the windows .net Compact framework shows a
    message telling "thread is being aborted".Since my application is
    started by a service.
    Please can anyone tell me where i am going wrong.How to terminate a
    thread properly in the above case without calling thread.abort.

    In lot of discussions they were discussions thread.abort is evil.Can
    anyone please explain how to terminate a thread without using
    thread.abort()

    please help me out in this

    Thanks in advance,
    RAGHU
  • Jon Skeet [C# MVP]

    #2
    Re: Problem with Thread.Abort()

    On Sep 30, 10:10 am, ragh...@gmail.c om wrote:

    <snip>
    In lot of discussions they were discussions thread.abort is evil.
    Yes indeed.
    Can anyone please explain how to terminate a thread without using
    thread.abort()
    See http://pobox.com/~skeet/csharp/threads/shutdown.shtml

    Jon

    Comment

    • raghudr@gmail.com

      #3
      Re: Problem with Thread.Abort()

      On Sep 30, 2:42 pm, "Jon Skeet [C# MVP]" <sk...@pobox.co mwrote:
      On Sep 30, 10:10 am, ragh...@gmail.c om wrote:
      >
      <snip>
      >
      In lot of discussions they were discussions thread.abort is evil.
      >
      Yes indeed.
      >
      Can anyone please explain how to terminate a thread without using
      thread.abort()
      >
      Seehttp://pobox.com/~skeet/csharp/threads/shutdown.shtml
      >
      Jon
      Hi jon,

      Thanks for the reply.

      I have started the thread in startsplash.How to end it in Stopsplash.

      How to use the class u have given in the link in stopsplash can u
      please explain more on this

      thanks,
      RAGHU

      Comment

      • Jon Skeet [C# MVP]

        #4
        Re: Problem with Thread.Abort()

        On Sep 30, 10:50 am, ragh...@gmail.c om wrote:

        <snip>
        I have started the thread in startsplash.How to end it in Stopsplash.
        >
        How to use the class u have given in  the link in stopsplash can u
        please  explain more on this
        You may well have to redesign the splash screen a little - show it on
        a different UI thread, and post an event to it to stop. But it should
        certainly be a graceful shutdown rather than thread abort.

        Jon

        Comment

        • raghudr@gmail.com

          #5
          Re: Problem with Thread.Abort()

          On Sep 30, 2:57 pm, "Jon Skeet [C# MVP]" <sk...@pobox.co mwrote:
          On Sep 30, 10:50 am, ragh...@gmail.c om wrote:
          >
          <snip>
          >
          I have started the thread in startsplash.How to end it in Stopsplash.
          >
          How to use the class u have given in  the link in stopsplash can u
          please  explain more on this
          >
          You may well have to redesign the splash screen a little - show it on
          a different UI thread, and post an event to it to stop. But it should
          certainly be a graceful shutdown rather than thread abort.
          >
          Jon
          Thanks Jon

          Comment

          Working...