Does a thread close automatically?

前端 未结 7 1229
萌比男神i
萌比男神i 2021-01-01 10:49

Im using a gmail class so that my app can send me notification over gmail.

Its done like this:

public static void SendMessage(string message)
{
    N         


        
7条回答
  •  被撕碎了的回忆
    2021-01-01 11:37

    The Abort() method throws an ThreadAbortException that you can handle:

    public void SendMessageThreaded()
    {
        try
        {
            // thread logic
        }
        catch (ThreadAbortException tae)
        {
            // thread was aborted, by t.Abort()
        }
        catch (Exception ex)
        {
            // other error
        }
    }
    

    By using

    t.Abort(myObject)
    

    you can "send" any object that helps you to handle the abort handling. You can use ExceptionState property to access that object.

提交回复
热议问题