3

我编写了一个作为标准控制台应用程序运行的 C# 工具。在程序结束时,我用来Console.Read()防止窗口关闭。这适用于我所有同事的 PC,除了一台。他从来没有看过我的申请。它完成了所有工作,但之后关闭。所有 PC 都运行 WinXP。你有什么主意吗?

我实现了一个 try-catch-finally,其中 finally 只包含Console.Read().

编辑:我添加了一些代码

Console.SetWindowSize(125, 40);
CopyToolBase ctb = null;
try
{
    DateTime startTime = DateTime.Now;
    TimeSpan duration;

    ctb = CopyToolBase.GetInstance(Defines.configPath);
    if (null == ctb)
    {
        throw new KopiertoolException();
    }

    if (null == ctb.GetNewestVersion())
    {
        throw new KopiertoolException();
    }

    if (!ctb.CheckCopy())
    {
        throw new KopiertoolException();
    }

    if (!ctb.CopyAndUnzip())
    {
        throw new KopiertoolException();
    }

    duration = DateTime.Now.Subtract(startTime);

    ctb.PrintSuccess("xxxxxxxx");
    ctb.PrintInfo("Gesamtdauer: " + ((duration.Hours == 0) ? "" : string.Format("{0:00} Std ", duration.Hours)) + string.Format("{0:00} Min {1:00} Sek", duration.Minutes, duration.Seconds));

    startTime = DateTime.Now;

    if (!ctb.StartTask())
    {
        throw new KopiertoolException();
    }

    duration = DateTime.Now.Subtract(startTime);

    if (duration.Minutes > 1)
    {
        ctb.PrintInfo("Dauer: " + ((duration.Hours == 0) ? "" : string.Format("{0:00} Std ", duration.Hours)) + string.Format("{0:00} Min {1:00} Sek", duration.Minutes, duration.Seconds));
    }
}
catch (KopiertoolException)
{
    ctb.WriteToLog();
}
catch (Exception ex)
{
    if (ctb == null)
    {
        Console.WriteLine("xxxxxxxxx");
        Console.WriteLine(ex.ToString());
    }
    else
    {
        ctb.PrintError("xxxxxxxxx");
        ctb.PrintError(ex.ToString());
        ctb.WriteToLog();
    }
}            
finally
{
    Console.Read();
}
4

1 回答 1

0

DLL您是否在课堂的任何部分都使用了导入的方法(或外部库) CopyToolBase

如果是这样,则可能是代码中某处抛出了损坏的状态异常,正常的 try/catch 块不会捕获该异常,因此可能存在异常,只是托管代码无法处理它并且没有办法,只能终止进程。

这是解释情况的链接:

我知道这是一个远射,但我想我会覆盖所有的基地

于 2012-09-18T16:07:35.127 回答