zoukankan      html  css  js  c++  java
  • .NET ------ 多线程的简单使用

    主要就是引用线程,实例化一个线程将需要执行的一个方法交给他,启动,执行完后自动关闭也可以手动关闭

    //引用
    using System.Threading;

    使用

     //实例化一个线程
     Thread t1 = new Thread(CopyGongZi);
    
     //启动
       t1.Start();

    注意,在线程中执行的方法要借助,静态变量进行赋值

        protected void btnAddUpt_Click(object sender, EventArgs e)
        {
            bllmdXinZiJiXiao bllmdXinZiJiXiao = new bllmdXinZiJiXiao();
            bllmdJiangJinList bllmdjiangjinlist = new bllmdJiangJinList();
    
            //bllmdJieSuanTitle bllmdjiesuantitle = new bllmdJieSuanTitle();
    
            string sqlUptlast = string.Empty;//修改-判断重复数据时使用
    
    
            string sCopyTitle = this.WebCtrl_JieSuanTitle2._HidJieSuanGuid;
            if (sCopyTitle == string.Empty)
            {
                WebMessageBox1.MessageBox_tishi(600, 300, 200, 100, "请选择需复制的标题");
                return;
            }
    
            //.GetListSelmdGongZi3("YearMouth", base.EnterpriseGuid, " and YearMouth='" + sYearMonth + "'");
            // List<ITEM.Model.qdMis4.mdJiangJinXiShu> mList = _bllJiSuanTitle.GetListSelmdJieSuanTitle3("Year");
            List<ITEM.Model.qdMis4.mdGongZi> mList = _bllGongZi.GetListSelmdGongZi3("YearMouthTitle", base.EnterpriseGuid, " and Ext09='" + this.WebCtrl_JieSuanTitle2._HidJieSuanGuid + "'");
            if (mList.Count > 0)
            {
                WebMessageBox1.MessageBox_tishi(600, 300, 200, 100, "复制后的标题已存在,请重新选择");
                return;
            }
            _xdeptguid = _XUserLogin.UserLoginOrganizationGuid;
            _xdeptcode = _XUserLogin.UserLoginOrganizationCode;
            _xdeptname = _XUserLogin.UserLoginOrganizationName;
            _xHidJieSuanMonth = this.WebCtrl_JieSuanTitle2._HidJieSuanMonth;
            _xHidJieSuanTitle = this.WebCtrl_JieSuanTitle2._HidJieSuanTitle;
            _xHidJieSuanGuid = this.WebCtrl_JieSuanTitle2._HidJieSuanGuid;
            xEnterpriseGuid = base.EnterpriseGuid;
            _xJianjinGuid = _JianjinGuid;
            xEnterpriseCode = base.EnterpriseCode;
            xEnterpriseName = base.EnterpriseName;
            xUserLoginGuid = _XUserLogin.UserLoginGuid;
            xUserLoginID = _XUserLogin.UserLoginID;
            xUserIP = _XUserLogin.UserIP;
    
            ITEM.Model.qdMis4.mdGongZi mold = _bllGongZi.GetModelSelmdGongZi3("GongZiSort,GongZiGuid", xEnterpriseGuid, _xJianjinGuid);
            xOld_GongZiSort = mold.GongZiSort;
            xOld_GongZiGuid = mold.GongZiGuid;
    
            _GongZiGuid_new = Guid.NewGuid().ToString();
            _GongZiGuid_old = xOld_GongZiGuid;// mold.GongZiGuid;
    
            //进行真正复制操作
            Thread t1 = new Thread(CopyGongZi); //实例化一个线程
            t1.Start(); //启动
    
            //查看
            Thread t2 = new Thread(GetChange); //实例化一个线程
            t2.Start(); //启动
            Response.Redirect("../qdExcel/ExcelMessage.aspx");
    
    
    
        }
    
        #region 设置静态变量进行赋值
    
        private static string _GongZiGuid_new;
        private static string _GongZiGuid_old;
        public static string _xdeptguid;
        private static string _xdeptcode;
        private static string _xdeptname;
        private static string _xHidJieSuanMonth;
        private static string _xHidJieSuanTitle;
        private static string _xHidJieSuanGuid;
        private static string _xJianjinGuid;
        private static string xEnterpriseGuid;
        private static string xEnterpriseCode;
        private static string xEnterpriseName;
    
        private static string xUserLoginGuid;
        private static string xUserLoginID;
        private static string xUserIP;
        private static string xOld_GongZiSort;
        private static string xOld_GongZiGuid;
    
        #endregion
    
    
        private void CopyGongZi()
        {
            #region 调用字段对应关系
            {
                string sGongZiGuid = string.Empty;
                //第一步,保存标题
                int k = 0;
    
                #region GongZi
                mdGongZi mdgongzi = new mdGongZi();
                mdgongzi.GongZiGuid = _GongZiGuid_new;// this.tbGongZiGuid.Text.Trim();//工资关键字
                mdgongzi.QiyeGuid = base.EnterpriseGuid;//云端标识关键字
                mdgongzi.QiyeCode = base.EnterpriseCode;//云端标识编码
                mdgongzi.QiyeName = base.EnterpriseName;//云端标识名称
                mdgongzi.DeptGuid = _xdeptguid;// _XUserLogin.UserLoginOrganizationGuid;//单位Guid
                mdgongzi.DeptCode = _xdeptcode;// _XUserLogin.UserLoginOrganizationCode;//单位编码
                mdgongzi.DeptName = _xdeptname;// _XUserLogin.UserLoginOrganizationName;//单位名称
                mdgongzi.YearMouth = _xHidJieSuanMonth;// this.WebCtrl_JieSuanTitle2._HidJieSuanMonth; //sYearMonth;// this.tbYearMouth.Text.Trim();//年月标识,格式yyyyMM
                mdgongzi.YearMouthTitle = _xHidJieSuanTitle;// this.WebCtrl_JieSuanTitle2._HidJieSuanTitle;// tbGongZiTitle.Text.Trim();// sYearMonth + "工资";// this.tbYearMouthTitle.Text.Trim();//工资标题
                mdgongzi.Ext09 = _xHidJieSuanGuid;// this.WebCtrl_JieSuanTitle2._HidJieSuanGuid;// tbGongZiTitle.Text.Trim();// sYearMonth + "工资";// this.tbYearMouthTitle.Text.Trim();//工资标题
                mdgongzi.e_XinZi_ShengHe_i = (int)ITEM.Inherits.Bll.CollEnum_Mis4.e_ShengHe.Enum.待提交;// Convert.ToInt32(this.ddle_XinZi_ShengHe_i.SelectedValue);//工资审核  0待提交 1待审核 2同意 -1打回
                mdgongzi.e_XinZi_ShengHe_s = ITEM.Inherits.Bll.CollEnum_Mis4.e_ShengHe.Enum.待提交.ToString();// this.tbe_XinZi_ShengHe_s.Text.Trim();//工资审核 0待提交 1待审核 2同意 -1打回
                //mdgongzi.XinZi_ShengHe_UserGuid = this.tbXinZi_ShengHe_UserGuid.Text.Trim();//工资审核人Guid
                //mdgongzi.XinZi_ShengHe_UserLoginID = this.tbXinZi_ShengHe_UserLoginID.Text.Trim();//工资审核人LoginID
                //mdgongzi.XinZi_ShengHe_Date = Convert.ToDateTime(this.tbXinZi_ShengHe_Date.Value);//工资审核时间
                //mdgongzi.XinZi_ShengHe_Remark = this.tbXinZi_ShengHe_Remark.Text.Trim();//工资审核说明
                //mdgongzi.Remark = this.tbRemark.Text.Trim();//备注
                //ITEM.Model.qdMis4.mdGongZi mold = _bllGongZi.GetModelSelmdGongZi3("GongZiSort", xEnterpriseGuid, _xJianjinGuid);
                mdgongzi.GongZiSort = xOld_GongZiSort;// mold.GongZiSort;
                mdgongzi.Flag = 0;//数据标识
                //mdgongzi.Flag_Remark = this.tbFlag_Remark.Text.Trim();//Flag标识说明,推荐使用枚举
                mdgongzi.OrderBy = 0;//排序编号
                mdgongzi.IsEnabled = 0;//是否禁用0-启用1-禁用
                mdgongzi.IsDelete = 0;//逻辑删除0-正常1-删除
                mdgongzi.CreateUserID = xUserLoginID;// _XUserLogin.UserLoginID;//数据创建者登录用户名
                mdgongzi.CreateUserGuid = xUserLoginGuid;// _XUserLogin.UserLoginGuid;//数据创建者的关键字Guid
                mdgongzi.Create_IP = xUserIP;// base.GetIp();//数据创建者IP地址
                mdgongzi.CreateTime = DateTime.Now;//创建时间
                mdgongzi.UpdateUserID = xUserLoginID;// _XUserLogin.UserLoginID;//数据修改这的登录用户名
                mdgongzi.UpdateUserGuid = xUserLoginGuid;// _XUserLogin.UserLoginGuid;//数据修改者的关键字Guid
                mdgongzi.Update_IP = xUserIP;// base.GetIp();//数据修改者IP地址
                mdgongzi.UpdateTime = DateTime.Now;//最后一次修改时间
                sGongZiGuid = mdgongzi.GongZiGuid;
    
    
                k = _bllGongZi.SetAddmdGongZi(mdgongzi);
                #endregion
    
                //第二步,导入数据
                #region copy
                if (k > 0)
                {
                    try
                    {
                        Dictionary<string, string> dic = new Dictionary<string, string>();
                        dic.Add("GongZiListGuid", "{Guid}");
                        dic.Add("GongZiGuid", sGongZiGuid);
    
    
                        dic.Add("Ext09", _xHidJieSuanGuid);
                        dic.Add("YearMouth", _xHidJieSuanMonth);
                        dic.Add("YearMouthTitle", _xHidJieSuanTitle);
                        //dic.Add("YearMouth", this.tbYearMouth.Value.Trim());
                        //dic.Add("YearMouthTitle", tbGongZiTitle.Text.Trim());
                        string sError = string.Empty;
                        int kk = _bllFileds.Set_Ex_DataCopy(xEnterpriseGuid, xEnterpriseCode, xEnterpriseName, "1", " GongZiGuid='" + _xJianjinGuid + "'", dic, xUserLoginGuid, xUserLoginID, xUserIP, ref sError);
                        if (kk > 0)
                        {
                            WebMessageBox1.MessageBox_tishi(600, 300, 200, 100, "工资复制成功,请在待提交中查看");
                            //string script = string.Empty;
                            //script += "<script language=javascript>";
                            //script += base.GetSrcriptContentByClick("btnSearch");
                            //script += "parent.WebPopupCancel();</script>";
                            //ClientScript.RegisterClientScriptBlock(this.GetType(), "WebPopupCancel", script);
                        }
                        else
                        {
                            WebMessageBox1.MessageBox_tishi(600, 300, 200, 100, "工资复制失败");
                            int kkk = _bllGongZi.SetDelmdGongZi(sGongZiGuid, xUserLoginGuid, xUserLoginID, xUserIP);
                        }
                    }
                    catch
                    {
                        WebMessageBox1.MessageBox_tishi(600, 300, 200, 100, "工资复制失败");
                        int kk = _bllGongZi.SetDelmdGongZi(sGongZiGuid, xUserLoginGuid, xUserLoginID, xUserIP);
                    }
                }
                else
                {
                    WebMessageBox1.MessageBox_tishi(600, 300, 200, 100, "工资复制失败");
                    int kk = _bllGongZi.SetDelmdGongZi(sGongZiGuid, xUserLoginGuid, xUserLoginID, xUserIP);
                }
                #endregion
            }
            #endregion
        }
    
        private void GetChange()
        {
            while (true)
            {
                string strsql1 = "select count(*) from tbmdGongZiList where QiyeGuid='" + xEnterpriseGuid + "' and GongZiGuid='" + _GongZiGuid_new + "'";
                string strsql2 = "select count(*) from tbmdGongZiList where QiyeGuid='" + xEnterpriseGuid + "' and GongZiGuid='" + _GongZiGuid_old + "'";
    
                object obj1 = _bllGongZiList.GetScalarByTx(strsql1);
                object obj2 = _bllGongZiList.GetScalarByTx(strsql2);
                if (obj1 != DBNull.Value && obj2 != DBNull.Value)
                {
                    base.ExcelUpLoadMessage = "当前正在复制:" + obj1.ToString() + " / " + obj2.ToString();
                }
                else
                {
                    return;
                }
    
                if (obj1 == obj2)
                {
                    base.ExcelUpLoadMessage = "复制运算完毕,共更新了" + obj1.ToString() + "条数据,点击这里返回<input type="button" onclick="javascript: window.history.back()" value="返回"/> ";
                    return;
                }
            }
        }
  • 相关阅读:
    ios初级必看视频
    Md5加密
    Jmail发送邮件
    NPOI Helper文档
    jquery 序列化
    mvc DropDownList默认选项
    获取HTML
    EntityFramework Reverse POCO Generator工具
    全选反选
    mvc导出EXCEL
  • 原文地址:https://www.cnblogs.com/obge/p/13274659.html
Copyright © 2011-2022 走看看