|
1金钱
本帖最后由 danedai 于 2014-7-12 17:10 编辑
我用winform开发,用到了WebBrowser控件,我给了WebBrowser一个地址,是个登录的地址,登录后会有cookie我想在winformr的代码下取到cookie,代码如下:
wbNC.Document.Cookie
在主线程是可以得到了,但我新开一个线程去取的时候就不行了,在网上查了资料说要用委托,还是不行
相关代码如下:
//启动重新连接服务器线程
Thread thReConnect = new Thread(new ParameterizedThreadStart(ReConnect));
thReConnect.SetApartmentState(ApartmentState.STA);
thReConnect.IsBackground = true;
thReConnect.Start();
private void ReConnect(object obj)
{
if (this.wbNC.InvokeRequired)//等待异步
{
ConnectDelegate fc = new ConnectDelegate(Connect);
this.wbNC.Invoke(fc);//通过代理调用刷新方法
}
else
{
Connect();
}
}
private delegate void ConnectDelegate();//代理
private void Connect()
{
//首先判断有没有登录,如果没有登录的话不要连接服务器
// if (wbNC.Document.Cookie != null) //已登录
{
//do something
}
}
请各位大神帮我看看
|
|