我弄了个发邮件方法,使用线程,我想在等待发送的时候可以停止发送,就是停止线程或者停止方法执行?怎么操作?
/// <summary>
        /// 启动发送邮件线程
        /// </summary>
        public void SendMailThread()
        {
            thmail = new Thread(new ThreadStart(DealWithMail));
            thmail.Start();
        }        /// <summary>
        /// 处理发送邮件
        /// </summary>
        public void DealWithMail()
        {
            SendMailClass.SendMessage(_mailInfo, out succee);
        }
SendMailClass这个类中的方法。

解决方案 »

  1.   

    在線程實作的方法中調用以下這行可以結束線程。Thread.CurrentThread.Abort();或者用 thmail.Abort();
      

  2.   

    需要设置 thmail.IsBackground = true;
      

  3.   

    我想到一个很土的办法:1、定义一个全局变量 
    bool returnValue = false;2、在异步或者是多线程里面 执行关键循环部位来句
    if(returnValue == true)
       return;//退出
    3、在要取消按钮上面来句
    returnValue = true;见笑了...
    不过还是找找有没有自带的 colse方法...
      

  4.   

    这种线程只能使用Abort函数退出了,我不知道别的办法。
      

  5.   

    ManualResetEvent rest=new ManualResetEvent(fasle);在取消事件中点亮信号
    rest.set();
    thread.join();  //等待线程终止在需要停止的线程或方法中等待信号
    if(rest.waitone(100))
     return;
      

  6.   

    这个问题俺研究很久了,源码下载,http://download.csdn.net/source/3357356