日期:2014-05-17  浏览次数:20775 次

关于线程同步?求助~

是这样的,我定义了两个线程执行同一个方法,总报许多奇怪错误,如:内存已损坏、数据更新失败等
经google,原来要用到线程同步什么的

想问怎么加等待?用sleep是不是线程会释放资源了?
怎样确保一个线程A执行完后让线程B执行;线程B执行完,A、B等待一定时间再轮流执行?
先谢谢各位了


定义两个公共线程:
        
public static Thread thread;//预警通知线程
public static Thread CQthead;//超期通知线程
//然后构造函数实例化线程


按钮事件


thread.Start("YJ");
CQthead.Start("CQ");


线程调用的方法:

 private void SendPickNotice(object Type)
        {
            DataStore dsItem = new DataStore();
            dsItem.LibraryList = "E:\\Net架构\\pbl\\baosi.p.md.escm.wm.dock.pbl";
            dsItem.DataWindowObject = "dw_wm_dock_inv_wharf_freedate";
            dsItem.SetTransaction(trans);
            
            //定义mip到港通知接口参数
            string subject = string.Empty;
            string type = Type.ToString();
            
            System.Configuration.AppSettingsReader appread = new System.Configuration.AppSettingsReader();
            string templateId = string.Empty;//获取模版ID
            //templateId = (string)appread.GetValue("DQTemplateId", templateId.GetType()); ;
            templateId = "140c404c0887e0e33e9bc1e4675adaee";
            StringBuilder values = new StringBuilder();//表单数据,json
            
            string flowstatus = "20";//默认20为流程待审状态
            string flowParams = string.Empty;//获取流程参数
            string noticeType = "CQTZ";//通知类型为:超期通知代码
            string result = string.Empty;//获取web服务接口的返回信息

            Dictionary<string, string> Unit = new System.Collections.Generic.Dictionary<string, string>();
            while (1 == 1)
            {
                //dsItem.SetTransaction(trans);
                dsItem.Retrieve();
                if