I try attaching certain custom document events but they fire sometime; sometimes they don't.
Worse, here is a scenario that you can test. I am not sure if this is my OS problem. Its a win7 machine, and it has IE 11 installed.
I start a localhost python web server and serve a static web page:
C:\code\forex> python -m SimpleHTTPServer 4542
And try to load the above web page in the webbrowser control. So my form's code is somewhat as follows:
using System;
using System.Diagnostics;
using System.Windows.Forms;
namespace winformWebBrowser
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
webBrowser1.DocumentCompleted += webBrowser1_DocumentCompleted;
webBrowser1.Navigate("http://localhost:4542");
}
void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
if (webBrowser1.ReadyState == WebBrowserReadyState.Complete)
{
Debug.Print("Ready");
}
}
}
}
I get the Ready message. But once I close the form, the local web server is also broken as a result.
PS C:\code\forex> python -m SimpleHTTPServer 4542
Serving HTTP on 0.0.0.0 port 4542 ...
127.0.0.1 - - [10/Jun/2015 19:06:42] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [10/Jun/2015 19:12:01] "GET / HTTP/1.1" 200 -
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 29758)
Traceback (most recent call last):
File "C:\Python27\lib\SocketServer.py", line 295, in _handle_request_noblock
self.process_request(request, client_address)
File "C:\Python27\lib\SocketServer.py", line 321, in process_request
self.finish_request(request, client_address)
File "C:\Python27\lib\SocketServer.py", line 334, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "C:\Python27\lib\SocketServer.py", line 655, in __init__
self.handle()
File "C:\Python27\lib\BaseHTTPServer.py", line 340, in handle
self.handle_one_request()
File "C:\Python27\lib\BaseHTTPServer.py", line 310, in handle_one_request
self.raw_requestline = self.rfile.readline(65537)
File "C:\Python27\lib\socket.py", line 476, in readline
data = self._sock.recv(self._rbufsize)
error: [Errno 10054] An existing connection was forcibly closed by the remote ho
st
----------------------------------------
So my question is does the webbrowser control work properly?