我有一个使用表单设计器创建的计时器(这使它成为主表单窗口的成员,对吧?)我在此类中以不同的方法停止计时器。目前我通过将它传递给另一个方法并分配给t
这个类的私有成员来让它工作。我意识到发生这种情况时它可能为空,但当我调试它并且它让我发疯时它不是。
System.NullReferenceException was unhandled by user code
Message=Object reference not set to an instance of an object.
private void domDocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
// do a doc scan here then remove the handler
var form = Form.ActiveForm as MainWindow;
form.pagesToVisit = docScan(b.Document, this.domain);
if (t != null) { t.Start(); }
// here i need to stop a timer that is a member of the main form
b.DocumentCompleted -= domDocumentCompleted;
}