gpt4 book ai didi

c# - 无法访问 Program.cs Main 方法上的处置对象

转载 作者:太空宇宙 更新时间:2023-11-03 21:25:26 25 4
gpt4 key购买 nike

我有一个具有两种不同形式的 WinForm 应用程序。如果第一个命令行参数是“下载”,则应该出现下载 表单。我在程序的 Main 方法的 Application.Run(new Download(args)); 行上得到一个 ObjectDisposedException

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;
}
}
}

enter image description here

更新:异常堆栈跟踪

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

最佳答案

您是否在下载表单的构造函数中执行类似的操作?

enter image description here

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

关于c# - 无法访问 Program.cs Main 方法上的处置对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27354405/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com