我有一个WinForm
应用程序有两种不同的形式。如果第一个命令行参数是“下载”,则应出现Download
表单。我在Main
方法的Application.Run(new Download(args));
行上获得ObjectDisposedException
行。无法访问Program.cs上的处置对象主要方法
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
if (args.Length > 0)
switch (args[0])
{
case "download":
if (args.Length == 4)
Application.Run(new Download(args));
break;
default:
Application.Run(new ApsisRunner(args));
break;
}
}
}
更新: 异常堆栈跟踪
at System.Windows.Forms.Control.CreateHandle()
at System.Windows.Forms.Form.CreateHandle()
at System.Windows.Forms.Control.get_Handle()
at System.Windows.Forms.Control.SetVisibleCore(Boolean value)
at System.Windows.Forms.Form.SetVisibleCore(Boolean value)
at System.Windows.Forms.Control.set_Visible(Boolean value)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at ApsisCampaignRunner.Program.Main(String[] args) in c:\Users\pedram.mobedi\Documents\GitHub\Postbag\ApsisCampaignRunner\Program.cs:line 31
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
它说什么处置对象是什么? – 2014-12-08 09:01:31
这可能是由于您的Main方法在Download对话框初始化之前退出。或者是WinForms中的Run()阻塞调用?父应用可能在它出现之前调用Dispose()。 – olitee 2014-12-08 09:03:45
@OmriAharon我添加了一个截图。 – Disasterkid 2014-12-08 09:04:25