我尝试附加某些自定义文档事件但有时会触发;有时他们不会。
更糟糕的是,这是一个可以测试的场景。我不确定这是否是我的操作系统问题。它是一台win7机器,安装了IE 11。
我启动了一个localhost python Web服务器并提供静态网页:
C:\code\forex> python -m SimpleHTTPServer 4542
并尝试在webbrowser控件中加载上述网页。所以我的表单代码有点如下:
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");
}
}
}
}
我收到Ready消息。但是一旦我关闭表单,本地Web服务器也会因此而中断。
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
----------------------------------------
所以我的问题是webbrowser控件是否正常工作?