2012-09-12 31 views
0

我已经创建了Windows应用程序..我需要添加参数到Main方法,所以我通过重载字符串[]参数改变了我的主要方法。Windows应用程序.exe没有通过修改更新主要方法

如果我改变任何改变程序类的主要方法它不通过我的应用程序.exe更新为什么?

复制的代码之前,从其他类

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

回答

0

添加参数mainb方法,我检查值之后改变的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()); 
    } 
} 
下面

复制的代码和调用的方法虽然没有直接回答这个问题,你可能有更好的运气使用

Environment.GetCommandLineArgs

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

相关问题