0

I have created windows application to .. I need to add arguments to Main method so I changed my main method by overloading string[] parameter.

if I change any changes to Program class main method it's not updating through my application .exe why?

copied code Before changing Program.cs

static class Program
{
    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main()
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Application.Run(new Form1());
    }
}

copied code below after adding arguments to mainb method i am checking for value and calling a method from other class

static class Program
{
    private static string x= string.Empty;
    private static string y= string.Empty;
    private static string z= string.Empty;

    public static void Main(string[] args)
    {
        try
        {
            if (args.Count() > 0)
            {
                if (args.Count() != 3)
                {
                    RootDirectory = args[0];
                    SourceFile = args[1];
                    DestinationFile = args[2];
                    Form1.GetCommandLineArgs(x, y, z);
                }
                else
                {
                    throw new Exception("");
                }
            }
            else
            {
                throw new Exception();
            }
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
        catch (Exception ex)
        {
            Common.AppUtilties.LogError(ex, "OnFailure, " + ex.Message);
            Environment.Exit(0);
        }
    }
}
4

1 回答 1

0

虽然没有直接回答这个问题,但你可能会更好地使用

Environment.GetCommandLineArgs

我通常将它用于 winforms,因为您可以从代码中的任何位置访问 args。

于 2012-12-03T15:35:29.870 回答