如何从另一个启动C#windows应用程序,带有传递和接收参数。 [英] How launch C# windows application from another one, with passing and receiving parameter.

查看:90
本文介绍了如何从另一个启动C#windows应用程序,带有传递和接收参数。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在同一个解决方案中有两个(第一,第二)C#Windows应用程序,我从第一个启动第二个应用程序,但是我需要两个传递参数来启动第二个应用程序来自

首先。



我尝试过:



//第一个项目

I have Two (First,Second) C# Windows application in same solution ,I launch second application from first but i need two pass parameter when launch second application from
First.

What I have tried:

//First Project

//do this code when the first project run 
Thread thread = new Thread(new ThreadStart(launchSecond));
            thread.Start();




private void launchSecond()
        {
            bool stop = false;
            while (!stop)
            {
                if (DateTime.Now >= fireDate)
                {
                    //SecondPaththe path of second project second.exe
                    Process.Start(SecondPath);
                    stop = true;
                }
                else
                    Thread.Sleep(1);
            }
        }



//如何发送参数以及如何在第二个项目中接收它

//以上代码工作成功。


//how send parameter and how receive it in second project
//Above code worked success.

推荐答案

请在此处查看答案: c# - 如何将命令行参数传递给WinForms应用程序? - 堆栈溢出 [ ^ ]
See the answers here: c# - How do I pass command-line arguments to a WinForms application? - Stack Overflow[^]


如果您有两个不同的流程(正如您的问题所示),那么可能会使用记录良好的 Process.Start方法(ProcessStartInfo)(System.Diagnostics) [ ^ ]。

另一方面,如果你在同一个应用程序中只有两个不同的线程(因为你的代码建议那么必须再使用一个可用的 .NET 线程类,有详细记录(您可能还会在网上找到许多代码示例)
If you have two different processes (as your question suggests) then might use the well documented Process.Start Method (ProcessStartInfo) (System.Diagnostics)[^].
On the other hand if you just have two different threads in the same application (as your code suggests then have to use one of the available .NET threading classes, again, well documented (you may also find many code sample on the web)


这篇关于如何从另一个启动C#windows应用程序,带有传递和接收参数。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆