110,557
社区成员
发帖
与我相关
我的任务
分享
private void btnSend_click(){
lock(arryList.SyncRoot)
{
foreach(string strGroup in OneLstGroup.Items)
{
poLedInfo []pos = m_boLedInfo.GetInfoByGroupName(strGroup);
foreach(poLedInfo po in pos)
{
//SendToSingleMemeber(po,/*po.Name+":"+*/strContent);
arryList.Add(new ListItem(strContent, po));
}
}
}
if(!m_bSending) //开启线程发送
{
Thread t = new Thread(new ThreadStart(SendFunc));
t.Start();
}
}
//发送线程
private void SendFunc()
{
m_bSending = true; //正在发送
lock(arryList.SyncRoot)
{
while(arryList.Count > 0)
{
Console.WriteLine("----------------{0}", arryList.Count);
ListItem lst = (ListItem)arryList[0];
poLedInfo po = lst.Value as poLedInfo;
SendToSingleMemeber(po, lst.Name);
arryList.RemoveAt(0);
Thread.Sleep(10);
}
}
Console.WriteLine("''''''----------------{0}", arryList.Count);
m_bSending = false;
}
public bool isFinished=false; //当前发送的邮件完成是否完成
private void btnSend_click(){
// lock(arryList.SyncRoot)
//{
m_bSending=false; //计划停止发送
while(!isFinished)
{
System.Threading.Thread.Sleep(30000); //给足够时间让当前发送邮件完成
}
//假设你下面的代码是在添加新邮件到列表
foreach(string strGroup in OneLstGroup.Items)
{
poLedInfo []pos = m_boLedInfo.GetInfoByGroupName(strGroup);
foreach(poLedInfo po in pos)
{
//SendToSingleMemeber(po,/*po.Name+":"+*/strContent);
arryList.Add(new ListItem(strContent, po));
}
}
//}
if(!m_bSending) //开启线程发送
{
Thread t = new Thread(new ThreadStart(SendFunc));
t.Start();
}
}
//发送线程
private void SendFunc()
{
m_bSending = true; //正在发送
//lock(arryList.SyncRoot)
//{
while(arryList.Count > 0 && m_bSending )
{
isFinished=false;
Console.WriteLine("----------------{0}", arryList.Count);
ListItem lst = (ListItem)arryList[0];
poLedInfo po = lst.Value as poLedInfo;
SendToSingleMemeber(po, lst.Name);
arryList.RemoveAt(0);
Thread.Sleep(10);
isFinished=true;
}
//}
Console.WriteLine("''''''----------------{0}", arryList.Count);
m_bSending = false;
}