日期:2014-05-17  浏览次数:21011 次

C# qq空间登录用的webbrowser 报错
调试的时候地址:http://user.qzone.qq.com/号码,试了好多次,偶尔能登陆成功,不成功的时候报错:未将对象引用设置到对象的实例,位置在代码那里注释出了,有时候也报错:“0”的值对于“index”无效 index”应介于 0 和 -1 之间,也是那个位置,我自己觉得可能是文档没完全加载或者线程问题,C#不熟,大家帮忙是什么原因或者怎么调整,代码也不多,谢谢大家

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;

namespace ReadCSV
{
    public partial class Form1 : Form
    {

        Thread loginThread1 = null;
        Thread loginThread2 = null;
        Mutex mutex = null;
        public delegate void webBrowserDocReq();
        private webBrowserDocReq wbdr;

        public Form1()
        {
            InitializeComponent();
            this.wbdr = new webBrowserDocReq(loginMethod);
        }     

        private void buttonLogin_Click(object sender, EventArgs e)
        {
            loginThread1 = new Thread(btnNavi);
            loginThread2 = new Thread(btnLogin);
            mutex = new Mutex();
            loginThread1.Start();
            loginThread2.Start();
        }
        private void btnNavi() 
        {
            lock (this)
            {
                mutex.WaitOne();
                webBrowser1.Navigate(new Uri(textUrl.Text.ToString()));
                Thread.Sleep(2000);
                mutex.ReleaseMutex();
            }
        }
        private void btnLogin()
        {

            lock (this)
            {