2012-09-12 33 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,因爲您可以從代碼中的任何位置訪問參數。

相關問題