public void callApp(string filename)
{
ServiceController service = new ServiceController("Pronto Data Server");
if (service.Status.Equals(ServiceControllerStatus.Stopped))
{
service.Start();
service.WaitForStatus(ServiceControllerStatus.Running);
}
Process process = new Process();
process.StartInfo.FileName = filename;
process.Start();
while (process.HasExited)
{
service.Stop();
service.WaitForStatus(ServiceControllerStatus.Stopped);
Environment.Exit(0);
}
}在程序中调用了以上的方法,服务及外部程序及执行成功,就是While循环里的语句在DEBUG时可执行,到真正应用起码却并没有执行,请问各位是什么问题呢?
{
ServiceController service = new ServiceController("Pronto Data Server");
if (service.Status.Equals(ServiceControllerStatus.Stopped))
{
service.Start();
service.WaitForStatus(ServiceControllerStatus.Running);
}
Process process = new Process();
process.StartInfo.FileName = filename;
process.Start();
while (process.HasExited)
{
service.Stop();
service.WaitForStatus(ServiceControllerStatus.Stopped);
Environment.Exit(0);
}
}在程序中调用了以上的方法,服务及外部程序及执行成功,就是While循环里的语句在DEBUG时可执行,到真正应用起码却并没有执行,请问各位是什么问题呢?
解决方案 »
- ~~~~~~~~~~~~~~~~请教,app.config文件要放在什么地方,放在同一个目录下读不到。
- 求教!!连接数据库错误
- 怎样绑定数据库的combobox控件不立即显示数据
- C#服务中取当前工作目录?
- 用哪种数据结构去存储城市省国家级联关系比较高效率?我目前想到的是两个字典
- Nhibernate的查询结果怎样跟DataGrid绑定?
- wpf在image控件用鼠标拖拽出矩形
- 一个类似资源管理器的程序
- 如何Clone一个类?
- system 线程 0x272c 已退出,返回值为 2 (0x2)。 求救
- csc 的 /unsafe 到底做了什么?
- 在asp.net中用框架,左侧菜单,右侧显示,可以开多窗口该怎么实现啊?求出大家了,十二分危急。
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.IO;
using System.ServiceProcess;
using System.Threading;namespace ProntoDataServerCall
{
public partial class Form1 : Form
{
public string filename="ProntoEdit Professional 2.0.exe";
public Form1()
{
InitializeComponent();
FileInfo file = new FileInfo(filename);
if (!file.Exists)
{
MessageBox.Show("Plesse locate the file", "Tips", MessageBoxButtons.OK);
openFileDialog1.ShowDialog();
filename = openFileDialog1.FileNames[0];
if (filename.Contains("ProntoEdit Professional"))
{
try
{
openFileDialog1.OpenFile();
callApp(filename);
}
catch
{
Environment.Exit(0);
}
}
}
else
callApp(filename);
}
public void callApp(string filename)
{
ServiceController service = new ServiceController("Pronto Data Server");
if (service.Status.Equals(ServiceControllerStatus.Stopped))
{
service.Start();
service.WaitForStatus(ServiceControllerStatus.Running);
}
Process process = new Process();
process.StartInfo.FileName = filename;
process.Start();
while (process.HasExited)
{
service.Stop();
service.WaitForStatus(ServiceControllerStatus.Stopped);
Environment.Exit(0);
}
}
}
}
while (true)
{
if(process.HasExited)
{
service.Stop();
service.WaitForStatus(ServiceControllerStatus.Stopped);
Environment.Exit(0);
}
else
{
Thread.Sleep(2000);
}
}