Answer the question
In order to leave comments, you need to log in
How to stop tracking an event?
There is this code
void funct()
{
webBrowser1.DocumentCompleted += (sender, e) =>
{
MessageBox.Show((sender as WebBrowser).Document.Url.ToString());
MessageBox.Show((sender as WebBrowser).Document.Cookie);
if ((sender as WebBrowser).Document.Url.ToString().Contains("chl_jschl_tk"))
{
string link = (sender as WebBrowser).Document.Url.ToString();
string cookie = CookieReader.GetCookie(link);
File.AppendAllText("link.txt", link);
File.AppendAllText("cookie.txt", cookie);
// Вот тут нужно перестать отслеживать событие так как оно происходит много раз
}
};
webBrowser1.Navigate("https://www.site.com/list1");
}
Answer the question
In order to leave comments, you need to log in
Move the handler to a separate method and unsubscribe using the operator -=
https://docs.microsoft.com/en-us/dotnet/csharp/pro...
The last point.
Something like this.
using System;
namespace ConsoleApp3
{
class Program
{
static void Main(string[] args)
{
var browser = new Browser();
browser.Bruh += (s, e) =>
{
Console.WriteLine("YAY");
browser.ClearEvents();
};
browser.Go();
browser.Go();
browser.Go();
}
}
class Browser
{
public event EventHandler Bruh;
public void Go()
{
Console.WriteLine("GO");
Bruh?.Invoke(this, null);
}
public void ClearEvents()
{
Bruh = null;
}
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question