I am trying to invoke one wpf application from another wpf application. The invoking wpf application makes the call
我正在尝试从另一个wpf应用程序调用一个wpf应用程序。调用wpf的应用程序进行调用
ProcessStartInfo BOM = new ProcessStartInfo();
BOM.FileName = @"D:\WPFAPPLICATION.exe";
BOM.Arguments = temp;
Process.Start(BOM);
Now in the invoked application, I try to retrieve the argument passed using
现在,在被调用的应用程序中,我尝试检索使用它传递的参数
string arguments =Process.GetCurrentProcess().StartInfo.Arguments;
However the arguments are not passed. why is this??
然而,争论并没有通过。这是为什么呢? ?
I also tried an alternative method where in:
我还尝试了另一种方法:
public partial class App : Application
{
public static String[] mArgs;
private void Application_Startup(object sender, StartupEventArgs e)
{
if (e.Args.Length > 0)
{
mArgs = e.Args;
}
}
}
}
However this did not work either!!! Please HELP!!
但是这也不管用!!请帮助! !
2 个解决方案
#1
3
Try using the Environment class to get the commandline arguments.
尝试使用Environment类获取命令行参数。
string[] args = Environment.GetCommandLineArgs
or use the string[] that is passed to your main method of your WPF Application (App.xaml.cs).
或者使用传递给WPF应用程序的主方法的字符串[]。
public partial class App : Application {
protected override void OnStartup(StartupEventArgs e) {
string[] args = e.Args;
}
}
Note: The call
注:电话
string arguments =Process.GetCurrentProcess().StartInfo.Arguments;
will not return any value. See this MSDN entry
不会返回任何值。看到这个MSDN条目
If you did not use the Start method to start a process, the StartInfo property does not reflect the parameters used to start the process. For example, if you use GetProcesses to get an array of processes running on the computer, the StartInfo property of each Process does not contain the original file name or arguments used to start the process.
如果没有使用Start方法来启动进程,则StartInfo属性不反映用于启动进程的参数。例如,如果您使用GetProcesses获取运行在计算机上的进程数组,则每个进程的StartInfo属性不包含用于启动进程的原始文件名或参数。
#2
2
Well I finally found a solution to my question if anyones interested. While in the calling application I maintained the same code I previously used:
如果有人感兴趣的话,我终于找到了我问题的答案。在调用应用程序中,我维护了以前使用过的代码:
ProcessStartInfo BOM = new ProcessStartInfo();
BOM.FileName = @"D:\WPFAPPLICATION.exe";
BOM.Arguments = temp;
Process.Start(BOM);
In the called application in order to receive arguments successfully I simply had to :
在所谓的应用程序中,为了成功地接收参数,我只需:
System.Text.StringBuilder strbuilder= new System.Text.StringBuilder();
foreach (String arg in Environment.GetCommandLineArgs())
{
strbuilder.AppendLine(arg);
barcode = arg;
}
psnfo = strbuilder.ToString();
I was not handling the arguments passed to the process in the correct manner
我没有以正确的方式处理传递给过程的参数
so upon displaying psnfo
所以在显示psnfo
The code returns :
代码返回:
D:\WPFAPPLICATION.exe temp
Source : http://www.codeproject.com/Questions/386260/Using-process-start-in-a-wpf-application-to-invoke
来源:http://www.codeproject.com/Questions/386260/Using-process-start-in-a-wpf-application-to-invoke
#1
3
Try using the Environment class to get the commandline arguments.
尝试使用Environment类获取命令行参数。
string[] args = Environment.GetCommandLineArgs
or use the string[] that is passed to your main method of your WPF Application (App.xaml.cs).
或者使用传递给WPF应用程序的主方法的字符串[]。
public partial class App : Application {
protected override void OnStartup(StartupEventArgs e) {
string[] args = e.Args;
}
}
Note: The call
注:电话
string arguments =Process.GetCurrentProcess().StartInfo.Arguments;
will not return any value. See this MSDN entry
不会返回任何值。看到这个MSDN条目
If you did not use the Start method to start a process, the StartInfo property does not reflect the parameters used to start the process. For example, if you use GetProcesses to get an array of processes running on the computer, the StartInfo property of each Process does not contain the original file name or arguments used to start the process.
如果没有使用Start方法来启动进程,则StartInfo属性不反映用于启动进程的参数。例如,如果您使用GetProcesses获取运行在计算机上的进程数组,则每个进程的StartInfo属性不包含用于启动进程的原始文件名或参数。
#2
2
Well I finally found a solution to my question if anyones interested. While in the calling application I maintained the same code I previously used:
如果有人感兴趣的话,我终于找到了我问题的答案。在调用应用程序中,我维护了以前使用过的代码:
ProcessStartInfo BOM = new ProcessStartInfo();
BOM.FileName = @"D:\WPFAPPLICATION.exe";
BOM.Arguments = temp;
Process.Start(BOM);
In the called application in order to receive arguments successfully I simply had to :
在所谓的应用程序中,为了成功地接收参数,我只需:
System.Text.StringBuilder strbuilder= new System.Text.StringBuilder();
foreach (String arg in Environment.GetCommandLineArgs())
{
strbuilder.AppendLine(arg);
barcode = arg;
}
psnfo = strbuilder.ToString();
I was not handling the arguments passed to the process in the correct manner
我没有以正确的方式处理传递给过程的参数
so upon displaying psnfo
所以在显示psnfo
The code returns :
代码返回:
D:\WPFAPPLICATION.exe temp
Source : http://www.codeproject.com/Questions/386260/Using-process-start-in-a-wpf-application-to-invoke
来源:http://www.codeproject.com/Questions/386260/Using-process-start-in-a-wpf-application-to-invoke