我的程序
1.线程 开启一个timer
2.timer里
string hehe=webBrowser1.DocumentText;//就报错
求各位大哥帮帮忙

解决方案 »

  1.   

    未处理 System.InvalidCastException
      Message="指定的转换无效。"
      Source="System.Windows.Forms"
     
      

  2.   

    string hehe=webBrowser1.DocumentText;
    这句会报这个错?确认是这句吗?不应该啊
      

  3.   

    string hehe=webBrowser1.DocumentText.ToString();
      

  4.   

       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;
            }
    测试一切正常啊
      

  5.   


    先开启一个线程,然后线程里开启TIMER,TIMER里再使用
     string s = this.WebBroswer.DocumentText;
      

  6.   

     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;
      

  7.   

    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;
     } 
      

  8.   


    直接这样,单用一个TIMER,CS程序有时候会卡住
      

  9.   

    你的timer是不是开太早了,最好在webBrowser1的DocumentCompleted后去执行timer.start,或者在使用webBrowser1.DocumentText前判断webBrowser1的状态是不是已经加载完成。