Esempio n. 1
0
        public static void callback(Object o)
        {
            string pc = DateTime.Now.ToString("yyyyMMddHHmmssfff");

            try
            {
                string[]     strData = new string[] { "", "", "", "", "" };
                callbackinfo smsc    = (callbackinfo)o;
                DataSet      ds      = smsc.Ds;
                //string sqlstr = "";
                //string updatesql = "";
                //string ids = "";
                for (int i = smsc.Startindex; i <= smsc.Endindex; i++)
                {
                    //发短信操作
                    string phone = smsc.Ds.Tables[0].Rows[i]["phone"].ToString();
                    string title = smsc.Ds.Tables[0].Rows[i]["title"].ToString();
                    string res   = "";
                    foreach (var item in phone.Split(','))
                    {
                        if (item != "")
                        {
                            res += SmsHelper.Send(item, "流量通科技", title, "liuliangt", "hvu7jcvzo81mvoo8endj4etoqmyhng8g", "d9cb15bb613274662803c4edfe121db12611", "");
                        }
                    }

                    if (res.Contains("000000"))
                    {
                        DTcms.BLL.dt_msg bll = new DTcms.BLL.dt_msg();
                        bll.UpdateState(true, System.Guid.Parse(smsc.Ds.Tables[0].Rows[0]["hid"].ToString()));
                        Console.WriteLine(smsc.Ds.Tables[0].Rows[0]["hid"].ToString() + "发送成功" + "-" + DateTime.Now.ToString("yyyyMMddHHmmss"));
                        Log.Info(smsc.Ds.Tables[0].Rows[0]["hid"].ToString() + "_" + res + "\r\n");
                    }
                    else
                    {
                        Console.WriteLine(smsc.Ds.Tables[0].Rows[0]["hid"].ToString() + "发送失败" + "-" + res + "-" + DateTime.Now.ToString("yyyyMMddHHmmss"));
                        Log.Error(smsc.Ds.Tables[0].Rows[0]["hid"].ToString() + "_" + res + "\r\n");
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex.ToString());
                Console.WriteLine(pc + "操作失败");
            }
        }
Esempio n. 2
0
        public static void smstimer()
        {
            isAllComplete = false;
            datacount     = 0;
            timercount    = 0;
            curxcendcount = 0; //当前线程结束数量
            xccount       = 0; //线程总数
            try
            {
                string[] strData = new string[] { "", "", "", "", "" };

                //string strSql = "select top 121 * from Send where show=0 order by astate asc";
                DTcms.BLL.dt_msg obll = new DTcms.BLL.dt_msg();
                DataSet          ds   = obll.GetList(121, " state!=1", " addtime asc");
                datacount = ds.Tables[0].Rows.Count;
                int xhmaxcount = 120;
                if (datacount < 121)
                {
                    xhmaxcount = datacount;
                }
                else
                {
                    timer.Enabled = false;
                }
                xccount = xhmaxcount % 8 == 0 ? xhmaxcount / 8 : Convert.ToInt32(xhmaxcount / 8) + 1;
                for (int i = 0; i < xccount; i++)
                {
                    //thread = new Task(exesms, smsc);
                    //thread.Start();

                    callbackinfo _callbackinfo = new callbackinfo();
                    _callbackinfo.Ds         = ds;
                    _callbackinfo.Startindex = (i * 8);
                    _callbackinfo.Endindex   = (i + 1) * 8 - 1;
                    if (_callbackinfo.Endindex > xhmaxcount - 1)
                    {
                        _callbackinfo.Endindex = xhmaxcount - 1;
                    }
                    var task = Task.Factory.StartNew(callback, _callbackinfo);
                    TaskList.Add(task);
                }
                //异步等待所有任务执行完毕
                Task.Factory.StartNew(x =>
                {
                    Task.WaitAll(TaskList.ToArray());
                    //标记所有任务运行完成
                    isAllComplete = true;
                    if (datacount > 120)
                    {
                        smstimer();
                    }
                    else
                    {
                        if (!timer.Enabled)
                        {
                            timer.Enabled = true;
                        }
                    }
                }, null);
            }
            catch
            {
                isAllComplete = true;
                timer.Enabled = true;
            }
            //Thread.Sleep(100);

            //if (datacount > 80)
            //{
            //    smstimer();
            //}
            //else
            //{
            //    if (!timer.Enabled)
            //    {
            //        timer.Enabled = true;
            //    }
            //}
        }