asp.net C#多线程后台获取网页源码

作者:袖梨 2022-06-25
 代码如下 复制代码

    public string GetWebPageResponse(string uriArg)
        {
            System.IO.Stream responseStream = System.Net.WebRequest.Create(uriArg).GetResponse().GetResponseStream();
            System.IO.StreamReader reader = new System.IO.StreamReader(responseStream);
            return reader.ReadToEnd();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            new System.Threading.Thread(delegate()
            {
                string strHtml = GetWebPageResponse(http://www.111com.net);
                // 后台执行部分
                this.Invoke((EventHandler)delegate
                {
                    richTextBox1.Text = strHtml;
                    // 操作UI部分
                });

            }).Start();
        }

相关文章

精彩推荐