asp.net 多线程

一般情况下,asp.net的代码是自上而下运行的,但有的情况需要多线程,比如发邮件这种操作,下面给出实现方案

定义类

public class ThreadWithEmailState
    {
        public string subject;
        public string content;
        public string receiver;
        public string ccs;
       
        public ThreadWithEmailState(string subject, string content, string receiver,string ccs)
        {
            this.subject = subject;
            this.content = content;
            this.receiver = receiver;
            this.ccs = ccs;
        }

        public void ThreadProc()
        {
            RISEmail.send(subject, receiver, content, ccs);
        }
    }

调用

ThreadWithEmailState tws = new ThreadWithEmailState(emailSubject, content[1], receiver, ccs);
Thread t = new Thread(new ThreadStart(tws.ThreadProc));
t.Start();

原文地址:https://www.cnblogs.com/kenny999/p/3110239.html