background
Free Selenium ChromeDriver. exe from memory. I use the following methods:
public override void DoJob(IJobExecutionConxt context, ILifetimeScope scope, {string [] args) Console. WriteLine (nameof (LoginReptiles1688Job) + "start -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --"); ChromeOptions options = null; IWebDriver driver = null; Try {...... } catch (Exception ex) { throw ex; } finally { driver? .Close(); // Close the chrome window driver? .Quit(); // Close the console app that was used to kick off the chrome window driver? .Dispose(); // Close the chromedriver.exe driver = null; options = null; detailtry = 0; shoptry = 0; Console. WriteLine (nameof (LoginReptiles1688Job) + "-- -- -- -- -- -- -- -- -- end -- -- -- -- -- -- -- -- -- --"); }}Copy the code
It did come down; However, the server did not wait for a few days to alarm again, or the old problem, behind the tampering for a long time, or did not solve the problem.
Problem to spy out
The root cause of the problem is that Selenium ChromeDriver. exe cannot be shut down properly. Use kill to kill the entire Chromedriver. Exe thread. No sooner said than done.
The main code
Chromedriver [DllImport("user32.dll", EntryPoint = "FindWindow")] private extern static IntPtr FindWindow(string lpClassName, string lpWindowName); [DllImport("user32.dll", EntryPoint = "SendMessage")] public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam); public const int SW_HIDE = 0; public const int SW_SHOW = 5; [DllImport("user32.dll", EntryPoint = "ShowWindow")] public static extern int ShowWindow(IntPtr hwnd, int nCmdShow); /// </summary> // </returns> public IntPtr GetWindowHandle() {string name = (Environment.CurrentDirectory + "\\chromedriver.exe"); IntPtr hwd = FindWindow(null, name); return hwd; } /// </summary> public void CloseWindow() {try {IntPtr HWD = GetWindowHandle(); // </summary> public void CloseWindow() {try {IntPtr HWD = GetWindowHandle(); SendMessage(hwd, 0x10, 0, 0); } catch {}} /// <summary> // exit chromedriver /// </summary> /// <param name="driver"></param> public void CloseChromeDriver(IWebDriver driver) { try { driver.Quit(); driver.Dispose(); } catch { } CloseWindow(); } #endregion exits chromedriver unexpectedlyCopy the code
conclusion
1, sure enough enough thorough, Chromedriver. exe each time normally shut down, memory usage is also normal.
Things have two sides, sometimes the opposite has always been a good way to solve the problem.
3, use this way, is equal to kill the entire process, so it is not suitable for multiple threads operation, otherwise there will be an interruption.