1

我有一个WinForm有两种不同形式的应用程序。如果第一个命令行参数是"download",则Download应该出现该表单。我得到了ObjectDisposedException关于我的程序方法的Application.Run(new Download(args));在线信息。Main

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()
4

2 回答 2

4

您是否在“下载的构造函数”表单中做类似的事情?

在此处输入图像描述

问题可能出在下载表单的代码中。您不应在构造函数中关闭或处置 Form。

于 2014-12-08T09:15:43.177 回答
1

您发布的代码很好,但是如果在您的 Download 类中的任何地方发生对象处理异常,它将被抛出调用堆栈,直到您看到它(主要方法),

原因是您尝试在处置表单后将其设置为可见。

您可以尝试中断 ObjectDisposed Exceptions 并找到它被抛出的确切行,您可以在 Debug -> Exceptions 下这样做。

于 2014-12-08T09:12:38.443 回答