【发布时间】:2019-10-17 08:07:36
【问题描述】:
您好,我正在尝试创建一个用 c# 编写的 Windows 窗体应用程序,它将启动、停止并监视它是否正在运行另一个控制台应用程序。
现在我可以在我的 Windows 应用程序上启动控制台应用程序,但是我如何为其 Console.ReadLine 提供值
这是我的代码:
Windows 应用程序:
int ProcessIDDaca = 111111111;
private void btnDacaStart_Click(object sender, EventArgs e)
{
try
{
using (Process myprocess = new Process())
{
myprocess.StartInfo.UseShellExecute = false;
myprocess.StartInfo.FileName = @"C:\Users\nx011116\Documents\MachineMonitor\CopyChimp_Server\bin\Debug\CopyChimpServer.exe";
//myprocess.StartInfo.FileName = @"C:\Program Files\Eltima Software\Virtual Serial Port Driver 9.0\vspdconfig.exe";
myprocess.StartInfo.CreateNoWindow = true;
if (btnDacaStart.Text == "Stop")
{
Process proc = Process.GetProcessById(ProcessIDDaca);
proc.Kill();
btnDacaStart.Text = "Start";
lblDacaID.Text = "";
}
else
{
myprocess.Start();
var s = myprocess.Id;
ProcessIDDaca = myprocess.Id;
lblDacaID.Text = s.ToString();
btnDacaStart.Text = "Stop";
}
}
}
catch (Exception ex)
{
}
}
控制台应用:
public static string copychimp_server = "";
public static int port_number = 0;
static void Main(string[] args)
{
Console.Write("Enter copychimp server: ");
//Here i need to provide
copychimp_server = Console.ReadLine();
Console.Write("Enter port number: ");
//Here i need to provide
port_number = Convert.ToInt16(Console.ReadLine());
}
还有为什么没有显示,但我可以看到它正在我的任务管理器上运行? 像编程初学者一样,我非常感谢您的帮助。 提前谢谢你
【问题讨论】:
标签: c# .net winforms console-application