想要发送多个信息 [英] Want to send multi msgs

查看:78
本文介绍了想要发送多个信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

发送了单个味精,但是当我尝试发送多个味精时,我必须等待thread.Sleep(10000)不好,如果我给出thread.Sleep(1000)或更少,这是行不通的
救救我

//////单个msg

single msg sent but when i try to send multi msgs i must wait thread.Sleep(10000)thats not good and if i give thread.Sleep(1000) or less this is not work
help me plz

/////Single msg

private void button2_Click(object sender, EventArgs e)
       {
           SmsClass sm = new SmsClass(cboPorts.Text);
           sm.Opens();
           sm.sendSms(txtPhone.Text, txtMessage.Text);
           sm.Closes();
           MessageBox.Show("Message Sent!");
       }




///////////////Multi msgs






////////////////Multi msgs



private void btnSendGrouped_Click(object sender, EventArgs e)
        {
            SmsClass sm = new SmsClass(cboPorts.Text);

             for (int a = 0; a <= MobileNumbers.Items.Count - 1; a++)
            {

                sm.Opens();
                sm.sendSms(MobileNumbers.Items[a].ToString(), GtxtMessage.Text);
                sm.Closes();
                Thread.Sleep(10000);
                MessageBox.Show("Message Sent Successfully");
            }

             sm = null;

推荐答案

您好,

为什么每次通过循环都关闭连接,然后为下一条消息重新打开它!太疯狂了!您应该打开连接,然后发送所有消息,然后关闭连接-将sm.Opens()和sm.Closes()移到循环外,然后删除Sleep().例如

Hi there,

Why do you close the connection every time through your loop then reopen it for the next message! That is insane! You should open the connection then send all your messages then close the connection - move the sm.Opens() and sm.Closes() outside the loop and remove the Sleep(). E.g.

private void btnSendGrouped_Click(object sender, EventArgs e)
{
    SmsClass sm = new SmsClass(cboPorts.Text);

    sm.Opens();

    for (int a = 0; a <= MobileNumbers.Items.Count - 1; a++)
    {
        sm.sendSms(MobileNumbers.Items[a].ToString(), GtxtMessage.Text);
    }

    sm.Closes();
    MessageBox.Show("Messages Sent Successfully");

    sm = null;
}



希望这会有所帮助,
Ed



Hope this helps,
Ed


这篇关于想要发送多个信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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