整个代码大概是这样的:
public abstract class ParentForm:System.Windows.Forms.Form{
...
public abstract bool Open();
}public class ChildForm: ParentForm {
public override bool Open(){
...
this.DocumentOpen(doc,printLayouts);
} public bool DocumentOpen(XmlDocument doc, DesignerLinkedPrintLayout[] printLayouts) {
if (doc != null) {
this.SetStatus("Reading Information...");
this.Progress = (int)Math.Ceiling(100 / 7.0F * 1.0F); Hashtable hash = new Hashtable(); hash.Add(doc, printLayouts);
ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(this.documentOpen), hash);
}
return true;
} private void documentOpen(object obj) {
...
this.Invoke(new EmptyParamDelegate(this.documentOpen));
} private void documentOpen(){
...
}}public class TestForm :System.Windows.Forms.Form{
...
private void btnOpen_Click(object sender, EventArgs e){
ParentForm frm = this.CreateForm();//这里得到的是一个ChildForm instance
if(frm.Open()){
this.ShowFrom(frm);
}elss{
frm.Dispose();
}
}
}现在有一个问题就是:
当我打开ChildForm然后关闭,再次就无法打开,老是提示System.ObjectDisposedException
错误如下:
Exception: System.ObjectDisposedException
Message: Cannot access a disposed object.
Object name: 'ChildForm'.
Source: System.Windows.Forms
at System.Windows.Forms.Control.MarshaledInvoke(Control caller, Delegate method, Object[] args, Boolean synchronous)
at System.Windows.Forms.Control.Invoke(Delegate method, Object[] args)
at System.Windows.Forms.Control.Invoke(Delegate method)
at FLogic.Workflow.Designer.WorkflowDesigner.WorkflowDesignerWorkForm.documentOpen(Object obj) in C:\Projects\ChildForm.cs:
at System.Threading._ThreadPoolWaitCallback.WaitCallback_Context(Object state)
at System.Threading.ExecutionContext.runTryCode(Object userData)
at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallbackInternal(_ThreadPoolWaitCallback tpWaitCallBack)
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback(Object state)
大家帮我找找是什么原因啊
每次指示的是 this.Invoke(new EmptyParamDelegate(this.documentOpen));这行出错.
public abstract class ParentForm:System.Windows.Forms.Form{
...
public abstract bool Open();
}public class ChildForm: ParentForm {
public override bool Open(){
...
this.DocumentOpen(doc,printLayouts);
} public bool DocumentOpen(XmlDocument doc, DesignerLinkedPrintLayout[] printLayouts) {
if (doc != null) {
this.SetStatus("Reading Information...");
this.Progress = (int)Math.Ceiling(100 / 7.0F * 1.0F); Hashtable hash = new Hashtable(); hash.Add(doc, printLayouts);
ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(this.documentOpen), hash);
}
return true;
} private void documentOpen(object obj) {
...
this.Invoke(new EmptyParamDelegate(this.documentOpen));
} private void documentOpen(){
...
}}public class TestForm :System.Windows.Forms.Form{
...
private void btnOpen_Click(object sender, EventArgs e){
ParentForm frm = this.CreateForm();//这里得到的是一个ChildForm instance
if(frm.Open()){
this.ShowFrom(frm);
}elss{
frm.Dispose();
}
}
}现在有一个问题就是:
当我打开ChildForm然后关闭,再次就无法打开,老是提示System.ObjectDisposedException
错误如下:
Exception: System.ObjectDisposedException
Message: Cannot access a disposed object.
Object name: 'ChildForm'.
Source: System.Windows.Forms
at System.Windows.Forms.Control.MarshaledInvoke(Control caller, Delegate method, Object[] args, Boolean synchronous)
at System.Windows.Forms.Control.Invoke(Delegate method, Object[] args)
at System.Windows.Forms.Control.Invoke(Delegate method)
at FLogic.Workflow.Designer.WorkflowDesigner.WorkflowDesignerWorkForm.documentOpen(Object obj) in C:\Projects\ChildForm.cs:
at System.Threading._ThreadPoolWaitCallback.WaitCallback_Context(Object state)
at System.Threading.ExecutionContext.runTryCode(Object userData)
at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallbackInternal(_ThreadPoolWaitCallback tpWaitCallBack)
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback(Object state)
大家帮我找找是什么原因啊
每次指示的是 this.Invoke(new EmptyParamDelegate(this.documentOpen));这行出错.
private void documentOpen(object obj) {
...
this.Invoke(ep);
}