How do I suppress a thread.abort() error C#?

2020-02-26 11:33发布

I am showing a splash screen on a background thread while my program loads. Once it loads I am aborting the Thread as it's only purpose was to show a Now Loading splash form.

My problem is that when aborting a Thread it throws a ThreadAbortException that the user can just click Continue on.

How do I deal with this? I was trying to suppress it like so -->

            try
        {
            Program.splashThread.Abort();
        }
        catch(Exception ex)
        {

        }

but I have a feeling that is going to get me yelled at here and it doesn't work any way.

Thanks!

8条回答
闹够了就滚
2楼-- · 2020-02-26 12:36

Why would you do that? Just set a flag that the thread polls, then eventually when the thread picks it up it'll close itself.

查看更多
爷的心禁止访问
3楼-- · 2020-02-26 12:38

Please refer to the following link obtained doing a Google search (first result returned):

http://msdn.microsoft.com/en-us/library/5b50fdsz.aspx

Pay special attention to this part:

When this method is invoked on a thread, the system throws a ThreadAbortException in the thread to abort it. ThreadAbortException is a special exception that can be caught by application code, but is re-thrown at the end of the catch block unless ResetAbort is called. ResetAbort cancels the request to abort, and prevents the ThreadAbortException from terminating the thread. Unexecuted finally blocks are executed before the thread is aborted.

查看更多
登录 后发表回答