简体   繁体   English

循环和Fiddlercore中的C#WebBrowser

[英]C# WebBrowser in loop and Fiddlercore

I use Fiddlercore to capture multiple url's at the same time inside a loop. 我使用Fiddlercore在一个循环中同时捕获多个URL。

Example: 例:

private void button1_Click(object sender, EventArgs e)
{
    // I have 2 url 
    string arr = new string[]{ url1, url2 };
    foreach(var url in arr)
    {
       new Webbrowser().Navigate(url);
    }

    Fiddler.FiddlerApplication.AfterSessionComplete 
        += new Fiddler.SessionStateHandler(FiddlerApplication_AfterSessionComplete);
    }

    // I will catch 2 oSession contain same string "a/b/c" in 2 URL from 2 Webbrowser in loop 
   int Count = 0;
   void FiddlerApplication_AfterSessionComplete(Fiddler.Session oSession)
   {
       if(oSession.fullUrl.contain("a/b/c"))
       {
           Count+= 1;
           richtextbox1.AppendText("oSession.fullUrl" + "\n");
       }

       if(Count == 2)
       {
           Count = 0;
           StopFiddler();
       }
   }

void StopFiddler()
{
    Fiddler.FiddlerApplication.AfterSessionComplete 
        -= new Fiddler.SessionStateHandler(FiddlerApplication_AfterSessionComplete);
}

This works but I have a problem. 这可行,但是我有问题。 Fiddlercore stops the capture session, but the web browser doesn't stop, it's still loading. Fiddlercore停止了捕获会话,但是Web浏览器没有停止,而是仍在加载。

How to stop the WebBrowser from loading after I get what I need. 得到所需信息后,如何阻止WebBrowser加载。

Use WebBrowser.Stop() to stop all loading. 使用WebBrowser.Stop()停止所有加载。

Cancels any pending navigation and stops any dynamic page elements, such as background sounds and animations. 取消任何待处理的导航并停止任何动态页面元素,例如背景声音和动画。

Edit: Also, you need to save a reference to those WebBrowser controls you're creating, so that you can actually call the Stop method for them. 编辑:另外,您需要保存对正在创建的WebBrowser控件的引用,以便您可以实际为它们调用Stop方法。 The way you use them now is quite strange and might lead to problems down the line (actually it led to problems already). 您现在使用它们的方式非常奇怪,可能会导致一系列问题(实际上已经导致了问题)。

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

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