我用3.5的框架做了一个发短信的客户端  用生成好的exe在2.0的上面运行 内存一直不停的飙升  数据一大程序就会死掉  我以为是版本问题 然后又重新用2.0的写了一个 放上去以后 内存依然很高   发送数量打的话程序还是会死的  真不知道是什么原因  我希望大家能帮我解决一下!  只要能帮我解决了 大不了我把我的分全给你你们

解决方案 »

  1.   

    很可能是内存泄露啊,用 WinDbg 调试一下!
      

  2.   

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.Timers;namespace TengXint
    {
        public partial class Form1 : Form
        {
            BLL.BLL_YDSendA bll_SendA = new BLL.BLL_YDSendA();
            BLL.BLL_YDSentPort sentport = new BLL.BLL_YDSentPort();
            BLL.BLL_YDFailA fail = new BLL.BLL_YDFailA();
            BLL.BLL_UPInfo upinfo = new BLL.BLL_UPInfo();
            BLL.BLL_SentReport sentreport = new BLL.BLL_SentReport();
            BLL.BLL_UserAcc useracc = new BLL.BLL_UserAcc();
            BLL.BLL_YDFeeA feea = new BLL.BLL_YDFeeA();
            BLL.BLL_Errors errors = new BLL.BLL_Errors();
            BLL.BLL_ChannelFee bchaneelfee = new BLL.BLL_ChannelFee();
           
            public Form1()
            {
                InitializeComponent();
                CheckForIllegalCrossThreadCalls = false;
            }        System.Timers.Timer t = new System.Timers.Timer();
            private void Form1_Load(object sender, EventArgs e)
            {
                try
                {
                    t.Interval = 5000;
                    t.Elapsed += new System.Timers.ElapsedEventHandler(SendMessage);
                    //到达时间的时候执行事件;   
                    t.AutoReset = true;
                    //设置是执行一次(false)还是一直执行(true);   
                    t.Enabled = true;
                    this.weburl.Text = "http://203.171.227.208/plan/Api/";
                    this.username.Text = "junxian";
                    this.Pwd.Text = "jx12312385";
                    this.zhangtai.Text = "等待发送......";
                    this.zhangtai.ForeColor = Color.Blue;
                    //代发、失败、剩余条数
                    this.daifa.Text = bll_SendA.Select_YDSendA2().Tables[0].Rows.Count.ToString();
                    this.shibai.Text = fail.Select_YDFail().Tables[0].Rows.Count.ToString();
                    this.label14.Text = bchaneelfee.SelectChanneFeeA().Tables[0].Rows[0]["A通道余额"].ToString();
                    //DataSet dsFeeA = ;
                    if (feea.SelectYDFeeA3().Tables[0].Rows.Count == 0)
                    {
                        feea.BLL_FeeA3();
                    }
                    Zt();
                }
                catch (Exception ex)
                {
                    //MessageBox.Show(ex.Message.ToString());
                    this.zhangtai.Text = "出现异常";
                    this.zhangtai.ForeColor = Color.Red;
                }
                finally
                {            }        }        /// <summary>
            /// 发送方法
            /// </summary>
            Random rand = new Random();
            public void SendMessage(object sender, EventArgs e)
            {
                try
                {
                    this.shibai.Text = fail.Select_YDFail().Tables[0].Rows.Count.ToString();
                    DataSet dsSelectSentA = bll_SendA.Select_YDSendA();
                    if (dsSelectSentA.Tables[0].Rows.Count > 0)
                    {
                        t.AutoReset = false;
                        t.Enabled = false;
                        string strcodeList = "";
                        string strCenten = dsSelectSentA.Tables[0].Rows[0]["内容"].ToString();
                        string strChcode = dsSelectSentA.Tables[0].Rows[0]["子号码"].ToString();                    string uname = useracc.SelectUser(strChcode).Tables[0].Rows[0]["账户名称"].ToString();                    for (int i = 0; i < dsSelectSentA.Tables[0].Rows.Count; i++)
                        {                        if (dsSelectSentA.Tables[0].Rows[i]["手机号码"].ToString().Trim() != "")
                            {
                                strcodeList += dsSelectSentA.Tables[0].Rows[i]["手机号码"].ToString() + ",";
                            }
                        }
                        //Encoding ecoding = Encoding.GetEncoding("GB2312");
                        //PGet postdata = new PGet();
                        //string rs = postdata.PostData(this.username.Text.Trim(), this.Pwd.Text.Trim(), strcodeList.Substring(0, strcodeList.Length - 1), strCenten, "1");
                        //MessageBox.Show(rs);
                       // rs = System.Web.HttpUtility.UrlDecode(rs.Trim(), ecoding);
                        int intRand = rand.Next(0, 9);
                        string rs = "";
                        if (intRand > 2)
                        {
                            rs = "result=0&faillist=15220225881,15220225882,&description=发送短信成功";
                        }
                        else
                        {
                            rs = "result=0&faillist=&description=发送短信成功";
                        }                    string[] strArry = rs.Split('&');
                        string[] result = strArry[0].Split('=');
                        string[] result2 = strArry[2].Split('=');                    string[] strArry2 = strArry[1].Split('=');
                        this.daifa.Text = bll_SendA.Select_YDSendA2().Tables[0].Rows.Count.ToString();
                        //所有号码集合
                        string[] strCode = strcodeList.Split(',');
                        //判断发送结果
                        switch (result[1])
                        {
                            case "0":                            //判断是否含有失败号码
                                if (strArry2[1].ToString() != "")
                                {
                                    int intSum = 0;
                                    for (int j = 0; j < strCode.Length - 1; j++)
                                    {
                                        //循环比较号码
                                        if (!strArry2[1].Contains(strCode[j]))
                                        {
                                            intSum = intSum + 1;
                                            //添加UPInfo数据
                                            upinfo.ADDUPInfo(strCode[j], strCenten, strChcode);
                                            //添加Sentport数据
                                            sentport.ADDSentport(strCode[j], strCenten, uname);
                                            //添加Sentreport数据
                                            sentreport.ADDSentport(strCode[j], strCenten, uname);
                                            //删除YDSendA的数据
                                            bll_SendA.Delete_YDSendA(dsSelectSentA.Tables[0].Rows[j]["ID"].ToString());
                                        }
                                        else
                                        {
                                            //添加YDfail数据
                                            fail.ADDFail(strCode[j], strCenten, strChcode);
                                            //添加Errors数据
                                            errors.ADDErrors(result2[1]);
                                            //删除YDSendA的数据
                                            bll_SendA.Delete_YDSendA(dsSelectSentA.Tables[0].Rows[j]["ID"].ToString());
                                        }                                }
                                    YDFreeTable(intSum);
                                    Zt();                            }
                                else//不存在失败号码
                                {                                for (int j = 0; j < strCode.Length - 1; j++)
                                    {
                                        upinfo.ADDUPInfo(strCode[j], strCenten, strChcode);
                                        sentport.ADDSentport(strCode[j], strCenten, uname);
                                        if (sentport.Selectport().Tables[0].Rows.Count > 0)
                                        {
                                            sentreport.ADDSentport(strCode[j], strCenten, uname);
                                        }
                                        else
                                        {
                                            sentreport.ADDSentport2(strCode[j], strCenten, uname);
                                        }
                                        bll_SendA.Delete_YDSendA(dsSelectSentA.Tables[0].Rows[j]["ID"].ToString());
                                    }
                                    YDFreeTable(strCode.Length - 1);
                                    Zt();
                                }
                                break;                        default:
                                for (int i = 0; i < strCode.Length - 1; i++)
                                {
                                    fail.ADDFail(strCode[i].ToString(), strCenten, strChcode);
                                    errors.ADDErrors(result2[1]);
                                    bll_SendA.Delete_YDSendA(dsSelectSentA.Tables[0].Rows[i]["ID"].ToString());
                                    this.shibai.Text = fail.Select_YDFail().Tables[0].Rows.Count.ToString();
                                }
                                Zt();                            break;
                        }
                        t.AutoReset = true;
                        t.Enabled = true;
                    }
                }
                catch
                {
                    this.zhangtai.Text = "出现异常";
                    this.zhangtai.ForeColor = Color.Red;
                }
            }        /// <summary>
            /// 再次绑定
            /// </summary>
           这个是代码