我正在使用GeckoFx 22。
按钮中的代码(下面)只能正常工作一次。当第二次按下按钮时(在程序的单次运行中),我得到一个错误NullReferenceException(在Navigate方法中)。有可能解决它吗?
class SomeClass
{
private GeckoWebBrowser _webBrowser;
public SomeClass()
{
if ( !Xpcom.IsInitialized )
{
Xpcom.Initialize( Application.StartupPath + "\\xulrunner" );
}
this._webBrowser = new GeckoWebBrowser();
}
public void Navigate()
{
this._webBrowser.Navigate( "http://google.com/" ); // here exception
}
}
...
private void Work()
{
try
{
var sc = new SomeClass();
sc.Navigate();
MessageBox.Show( "Done" );
}
catch ( Exception exception )
{
MessageBox.Show( exception.Message );
}
}
private void button1_Click( object sender, EventArgs e )
{
Thread thread = new Thread( Work );
thread.SetApartmentState( ApartmentState.STA );
thread.Start();
}
...