Problem with Thread.Abort()

R

raghudr

Hi all,

I am implemeting a splash screen in C#

I got a useful link from here :-
http://www.codersource.net/csharp_splash_screen.aspx

//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(DoSplash));
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 (ThreadAbortException abortException)
{
Thread.ResetAbort();

//
Console.WriteLine((string)abortException.ExceptionState);
}

Thread.Sleep(1000);


}

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
 
R

raghudr

On Sep 30, 10:10 am, (e-mail address removed) wrote:



Yes indeed.


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
 
J

Jon Skeet [C# MVP]

On Sep 30, 10:50 am, (e-mail address removed) wrote:

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
 
R

raghudr

On Sep 30, 10:50 am, (e-mail address removed) wrote:




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
 

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