是否一个线程自动关闭? [英] Does a thread close automatically?

查看:138
本文介绍了是否一个线程自动关闭?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Gmail的类即时通讯让我的应用程序可以给我发过Gmail的通知

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

它是这样完成的:

public static void SendMessage(string message)
{
    Notification.message = message;

    Thread t = new Thread(new ThreadStart(SendMessageThreaded));
    t.Start();
}

和螺纹功能是这样的:

private static void SendMessageThreaded()
{
    try
    {
        if (Notification.message != "")
            RC.Gmail.GmailMessage.SendFromGmail("accname", "accpass", "email", "subject", Notification.message);

        Notification.message = "";
    }
    catch
    { }
}



所以经过 SendMessageThreaded 运行,不是靠近自己或我一定要

So after SendMessageThreaded is run, does it close by itself or do i have to

t.Start()
t.Abort()

还是什么?

推荐答案

该线程需要启动一次 - 此时它会执行分配给它的退出代码块。

The thread needs to be started once - at which point it will execute the code block assigned to it and exit.

您不需要明确清理在大多数情况下,螺纹(除非你想早点例如跳伞)

You don't need to explicitly clean up the thread in most cases (unless you want to bail out early for example )

这篇关于是否一个线程自动关闭?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆