Esempio n. 1
0
        private void CallBackMethod(IAsyncResult ar)
        {
            string msg = string.Empty;
            //runEvent re = (runEvent)ar.AsyncState;
            AsyncResult result = (AsyncResult)ar;
            runEvent    re     = (runEvent)result.AsyncDelegate;

            msg = re.EndInvoke(ar);
            //将值传递出去
            ErrMsg obj = (ErrMsg)ar.AsyncState;

            obj.errmsg.Add(msg);
            //this.errMsg.Add(obj.ToString(), msg);
        }
Esempio n. 2
0
        public string SP_TEST_STOCKIN(List <string> ListData, string MYGROUP, string EMP, string EC, string LINE, int Total)
        {
            #region 开启多个线程来处理数据
            int x = 0;
            Dictionary <int, List <string> > diclistesn = new Dictionary <int, List <string> >();
            List <string> esndata = new List <string>();

            for (int i = 0; i < ListData.Count; i++)
            {
                esndata.Add(ListData[i]);
                x++;
                if (x >= 1)
                {
                    diclistesn.Add(i, esndata);
                    x       = 0;
                    esndata = new List <string>();
                }
                else
                {
                    if ((i + 1) == ListData.Count)
                    {
                        diclistesn.Add(i, esndata);
                    }
                }
            }
            AsyncCallback re = new AsyncCallback(CallBackMethod);
            ErrMsg        em = new ErrMsg();
            int           h  = 0;
            foreach (int it in diclistesn.Keys)
            {
                if (h == 0)
                {
                    EC = "OK";
                }
                else
                {
                    EC = "KK";
                }
                h++;
                deleevnet = new runEvent(_sp_test_stockin);
                ListIasyncresult.Add(deleevnet.BeginInvoke(diclistesn[it], MYGROUP, EMP, EC, LINE, diclistesn[it].Count, re, em));
            }
            while (true)
            {
                bool flag = true;
                foreach (IAsyncResult item in ListIasyncresult)
                {
                    flag &= item.IsCompleted;
                }
                if (flag)
                {
                    break;
                }
            }
            for (int r = 0; r < em.errmsg.Count; r++)
            {
                MessageBox.Show(em.errmsg[r]);
            }
            #endregion
            return("OK");
        }