2014-03-04 37 views
0
string format="@\"\"\"{0}\"\" \"\"{1}\"\" \"\"{2}\"\"\",Id, ProjectId, refresh"; 

IM存储上述作为字符串的大小大于或等于零且小于并将其传递到processstart(APPNAME,格式)。 的功能如下。传递参数控制台应用误差如下:索引(基于零)必须大于参数列表

public void ProcessStart(string AppName, string format) 
    { 
     try 
     { 
      ProcessStartInfo StartInfo = new ProcessStartInfo(System.Configuration.ConfigurationManager.AppSettings[AppName].ToString()); 
      StartInfo.Arguments = string.Format(format); 
      StartInfo.CreateNoWindow = true; 
      StartInfo.WindowStyle = ProcessWindowStyle.Hidden; 
      Process.Start(StartInfo); 
     } 
     catch (Exception ex) 
     { 
      throw ex; 
     } 
    } 
+0

你能告诉你传递的参数? – BenM

回答

2

不能在格式字符串中添加参数,这应该工作:

string format = "@\"\"\"{0}\"\" \"\"{1}\"\" \"\"{2}\"\"\""; 
var args = string.Format(format, Id, ProjectId, refresh); 
StartInfo.Arguments = args ; 
1

format string看起来聚集串与参数时 即时得到所提到的错误。

string格式更改为:

string format="@\"\"\"{0}\"\" \"\"{1}\"\" \"\"{2}\"\"\"; 

然后

StartInfo.Arguments = string.Format(format, Id, ProjectId, refresh); 
相关问题