我在控制台应用程序X中有一个c#方法,这启动了一个进程;控制台应用程序Y(用相同的c#解决方案编写)。 App Y然后在Excel 2010工作簿中激发vba宏。如何杀死Excel
对于在wkbook VBA我已经添加了一些代码来强制运行时错误1004
WinForm的使用过程中的事件,使用表格定时器,杀死进程引发的测试目的。它正在按照程序进行工作,我只是试图让它做更多一点。 为什么当我杀死进程时,XL在发现错误的时候保持打开状态?我如何找到摆脱XL实例的方式,如果它仍然存在,何时杀死进程,然后将错误消息发回到我的winForm?
(PS下面的代码是很熟悉,但这个问题不是一式两份)
private int elapsedTime;
private Process p;
private System.Windows.Forms.Timer myTimer;
const int SLEEP_AMOUNT = 1000;//1s
const int MAXIMUM_EXECUTION_TIME = 5000;//5s
private void btRunReport_Click(object sender, EventArgs e) {
btRunReport.Enabled = false;
lbStatusUpdate.Text = "Processing..";
//instantiate a new process and set up an event for when it exits
p = new Process();
p.Exited += new EventHandler(MyProcessExited);
p.EnableRaisingEvents = true;
p.SynchronizingObject = this;
elapsedTime = 0;
this.RunReportScheduler();
//add in a forms timer so that the process can be killed after a certain amount of time
myTimer = new System.Windows.Forms.Timer();
myTimer.Interval = SLEEP_AMOUNT;
myTimer.Tick += new EventHandler(TimerTickEvent);
myTimer.Start();
}
private void RunReportScheduler() {
p.StartInfo.FileName = @"\\fileserve\department$\ReportScheduler_v3.exe";
p.StartInfo.Arguments = 2;
p.Start();
}
private void MyProcessExited(Object source, EventArgs e){
myTimer.Stop();
btRunReport.Enabled = true;
lbStatusUpdate.Text = "Start";
}
void TimerTickEvent(Object myObject, EventArgs myEventArgs) {
myTimer.Stop();
elapsedTime += SLEEP_AMOUNT;
if (elapsedTime > MAXIMUM_EXECUTION_TIME)
{p.Kill();}
else
{myTimer.Start();}
}
我读了标题,并认为这是另一个人恨微软。 – 2012-03-19 21:03:57
认为标题的变化可能有助于 – whytheq 2012-03-19 21:05:09