繁体   English   中英

如何在C#线程中读取Cookie文件

[英]How to read cookie files in c# thread

我具有用于读取C#中的cookie文件的此功能:

private void getdocument()
{
 while (true)
 {
 MessageBox.Show(webBrowser1.Document.Cookie);
 }
}

我这样调用它:

private void Form1_Load(object sender, EventArgs e)
{
 Thread MyThread = new Thread(new ThreadStart(getdocument));
 MyThread.Start();
}

但是我遇到一个错误:

未处理System.InvalidCastException

指定的演员表无效。

如何解决这个问题?

在此处输入图片说明

正如您在“对象层次结构”中看到的那样, WebBrowser结构继承自System.Windows.Forms.Control ,因此您需要从创建它的线程中使用它。

解决:

private void getdocument()
{
    while (true)
    {

        this.Invoke((MethodInvoker) delegate
            {
                MessageBox.Show(webBrowser1.Document.Cookie);
            });
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM