I have an application which uses Webbrowser control to navigate to a few vendor sites and scrape reporting. Because there are several accounts with one vendor, I need to have the browser end its session and clear any set cookies. I am using API calls to wininet.dll for both and am able to achieve the desired result. However, intermittently, I get what appears to be a deadlock on the InternetSetOption for INTERNET_OPTION_END_BROWSER_SESSION.
It is very linear code and InternetSetOption is called from a single thread in one place. What makes it difficult to figure out is that while running in debug, I've only very rarely been able to reproduce the problem. As soon as I compile and run outside of VS, it will happen shortly after. I isolated it to that by pumping messages to the console as it runs.
The few times I've been able to catch the problem while debugging, it just shows InternetSetOption as the next statement and sits, no exceptions or errors, nothing in the output window. InternetSetOption should return boolean, but the program will go no further and I never get any return from the API call. I tried look at the last error message thrown, but in this case it doesnt help, as it never throws an error.
Anyone have any input as to what I can further do to debug this?
Declared as:
[DllImport("wininet.dll", SetLastError = true, CharSet = CharSet.Auto)]
private static extern bool InternetSetOption(
IntPtr hInternet,
int dwOption,
IntPtr lpBuffer,
int lpdwBufferLength);
And called by:
InternetSetOption(IntPtr.Zero, 42, IntPtr.Zero, 0);