C#主线程获取子线程值

        private static void GetFirstPageInfo(string pagedata)
        {
            MatchCollection mc = Regex.Matches(pagedata, @everyArray[1]);//(.*?)
            if (mc.Count > 0)
            {
                sonpagecount = mc.Count;
                threads = new Thread[sonpagecount];
                string[] pagestr = new string[8];
                for (int i = 0; i < sonpagecount; i++) //遍历抓取到的信息,取出准确的数据
                {


                    GetWebPage gw = new GetWebPage(pagestr);//实例化详细页面获取类
                    gw.getback += new GetWebPage.GetBackData(gw_getback);//为类定义方法委托
                    Thread th = new Thread(gw.ThreadPoolCallBack);//申明一个新线程
                    threads[i] = th;
                    th.Start();//开始新线程
                    th.Join();//主线程阻塞方法
                }
            }
        }
        ///
        /// 详细页面信息返回调用方法
        ///
        ///
        static void gw_getback(string[] str)
        {
                GetSecondPageInfo(str);//对获取到的详细信息进一步处理
        }
        ///
        /// 详细子页面操作
        ///
        ///
        private static void GetSecondPageInfo(string[] pagedata)
        {
            //对返回数据进行相关操作
        }
    ///
    /// 获取招标详细内容
    ///
    class GetWebPage
    {
        public delegate void GetBackData(string[] str);//委托方法
        public event GetBackData getback;//定义调用委托事件
        public void ThreadPoolCallBack(Object threadContext)
        {
            GetPageContent(_pageurl);
        }
        ///
        /// 获取指定页面数据
        ///
        /// 页面地址
        private void GetPageContent(string url)
        {
                if (getback != null)
                {
                    getback(result);//信息获取完后触法委托事件
                }
        }
       
    }

posted @ 2013-05-17 16:05  BicycleBoy  阅读(1235)  评论(0编辑  收藏  举报