1

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?

deostroll
  • 11,661
  • 21
  • 90
  • 161
  • "An existing connection was forcibly closed" should never be surprise when the user closes the window. The browser is no more. Resilient web servers know how to deal with that. Simple ones, well, they don't. – Hans Passant Jun 10 '15 at 14:53
  • Ideally the web browser control shouldn't do that, am I right? At least IE (the actual browser) doesn't... – deostroll Jun 10 '15 at 15:16
  • @deostroll, what about running the same page against the same server in Firefox or Chrome? How is the server holding on? Also, I suggest you [use WebBrowser feature control](http://stackoverflow.com/a/18333982/1768303), regardless of how trivial is your page. – noseratio Jun 10 '15 at 17:20
  • @Noseratio where do I write that code and call it? – deostroll Jun 11 '15 at 05:09
  • @deostroll, you can find a complete example [here](http://stackoverflow.com/a/28626667). – noseratio Jun 11 '15 at 07:49
  • @Noseratio yeah but the issue still replicates. I guess this is something to do with the cache. Hence I've resorted to appending some junk querystring to force the control to request from server everytime... – deostroll Jun 11 '15 at 09:11

0 Answers0