当前位置:编程学习 > C#/ASP.NET >>

线程内调取webBrowser1.DocumentText报错

我的程序
1.线程 开启一个timer
2.timer里
string hehe=webBrowser1.DocumentText;//就报错


求各位大哥帮帮忙
--------------------编程问答-------------------- 也不说个具体什么错。。。。

反正线程里操作ui,需要为委托 --------------------编程问答-------------------- 未处理 System.InvalidCastException
  Message="指定的转换无效。"
  Source="System.Windows.Forms"
  --------------------编程问答-------------------- 怎么用委托呢? --------------------编程问答-------------------- 谢谢2楼的哥哥 --------------------编程问答--------------------
引用 2 楼 nicejfs 的回复:
未处理 System.InvalidCastException
  Message="指定的转换无效。"
  Source="System.Windows.Forms"

string hehe=webBrowser1.DocumentText;
这句会报这个错?确认是这句吗?不应该啊 --------------------编程问答-------------------- 确认是这句,gxingmin --------------------编程问答-------------------- 有人能帮帮忙吗 --------------------编程问答-------------------- string hehe=webBrowser1.DocumentText.ToString(); --------------------编程问答--------------------    public MyHtmlForm()
        {
            InitializeComponent();
            this.WebBroswer.Navigate("http://www.baidu.com");
            timer = new Timer();
            timer.Tick += new EventHandler(timer_Tick);
            timer.Interval = 1000;
            timer.Enabled = true;
            timer.Start();
        }

        void timer_Tick(object sender, EventArgs e)
        {
            string s = this.WebBroswer.DocumentText;
        }
测试一切正常啊 --------------------编程问答--------------------
引用 8 楼 gxingmin 的回复:
string hehe=webBrowser1.DocumentText.ToString();

不好使,和你之前说过的线程操作UI,需要委托有关 --------------------编程问答--------------------
引用 9 楼 yqb_6280180 的回复:
public MyHtmlForm()
        {
            InitializeComponent();
            this.WebBroswer.Navigate("http://www.baidu.com");
            timer = new Timer();
            timer.T……


先开启一个线程,然后线程里开启TIMER,TIMER里再使用
 string s = this.WebBroswer.DocumentText; --------------------编程问答--------------------  private void button13_Click(object sender, EventArgs e)
        {
            t = new Thread(new ThreadStart(OpenTime1));
            t.Start();        }

     private void OpenTime1()
        {
                timer2.Interval = 1000;
                timer2.Start();
                Application.Run();
        }

   private void timer2_Tick(object sender, EventArgs e)
        {
            string cuan = this.webBrowser1.DocumentText;
} --------------------编程问答-------------------- private void button13_Click(object sender, EventArgs e)
         {
OpenTime1(); //为什么用线程,直接这样不行吗
             }
 
     private void OpenTime1()
         {
                 timer2.Interval = 1000;
                 timer2.Start();
                // Application.Run();
         }
 
   private void timer2_Tick(object sender, EventArgs e)
         {
             string cuan = this.webBrowser1.DocumentText;
 }  --------------------编程问答--------------------
引用 13 楼 gxingmin 的回复:
private void button13_Click(object sender, EventArgs e)
         {
OpenTime1(); //为什么用线程,直接这样不行吗
             }
 
     private void OpenTime1()
         {
                 timer2.I……


直接这样,单用一个TIMER,CS程序有时候会卡住 --------------------编程问答-------------------- 我主要就是为了循环检测 一个网页里指定位置的字符窜是否是我想要的,如果不是有音乐提醒。 --------------------编程问答-------------------- 你的timer是不是开太早了,最好在webBrowser1的DocumentCompleted后去执行timer.start,或者在使用webBrowser1.DocumentText前判断webBrowser1的状态是不是已经加载完成。
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,