线程执行带参数方法

using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;

namespace AAAAAA
{
    class AAA
    {
        public static void Main()
        { 
            Thread t = new Thread(new ParameterizedThreadStart(B));
            t.Start("B");
            
            Console.Read();
        }
        
        private static void B(object obj)
        {
            Console.WriteLine("Method {0}!",obj.ToString ());        
        }
    }
}


Thread thread2 = null;

if (thread2 == null)
{
thread2 = new Thread(new ParameterizedThreadStart(BatchSendMsg));
thread2.IsBackground = true;
thread2.Start(phonelist);
}
else if (thread2.ThreadState == (System.Threading.ThreadState.Background | System.Threading.ThreadState.Unstarted))
{
thread2.Start(phonelist);
}
else if (thread2.ThreadState == System.Threading.ThreadState.Stopped)
{
thread2 = new Thread(new ParameterizedThreadStart(BatchSendMsg));
thread2.IsBackground = true;
thread2.Start(phonelist);
}

 


public static void BatchSendMsg(object phonelist)
{

string[] ArrayPhone = phonelist as string[];
foreach (string phone in ArrayPhone)
{
string phonetemp = phone.Trim('\'');
T9.Util.LogUtil.WriteLog("号码:" + phonetemp, "weblog");
CKXD.Common.SendSMS sendSMS = new CKXD.Common.SendSMS();
string SMSContent = ProUtil.JKGJSendConent;
int sendresult = sendSMS.SmsSend(SMSContent, phonetemp.ToString(), "健康管家", "weblog");
string sql = string.Format(@"update wu_jkgjorder set UC_sendstate={1},updatetime=now() where UC_telphone='{0}';", phonetemp, sendresult == 1 ? 1 : sendresult == 0 ? 2 : 0);
T9.Util.LogUtil.WriteLog("更新短信状态语句:" + sql, "weblog");
T9.Common.CommonDal.ExecuteSql(string.Format(@"update wu_jkgjorder set UC_sendstate={1},updatetime=now() where UC_telphone='{0}';", phonetemp, sendresult == 1 ? 1 : sendresult == 0 ? 2 : 0));

}

}

 

posted @ 2020-04-22 20:46  .net&new  阅读(348)  评论(0编辑  收藏  举报