WaitForExit进程处于活动状态时是否可以运行代码?

时间:2019-05-06 23:21:07

标签: c# process overlay clock

我正在尝试将叠加时钟添加到基本上显示时间的程序中。但是,它还会打开充当广告的Powerpoint节目。我已经通过Powerpoint上方的窗体和标签添加了第二次显示,但是由于我依赖于Process.WaitForExit()函数,因此无法在Powerpoint运行时更新时钟。我该如何解决?

PowerPoint代码如下所示:

PptxClock p = new PptxClock();
Process powerPoint = new Process();

//Start the time display over the powerpoint slides
p.Show();

 //Now it's time to open the powerpoint
powerPoint.StartInfo.FileName = ppfile;
powerPoint.Start();
// increment the counter so next iteration we play the next file in the list
slidetoplay += 1;

powerPoint.WaitForExit();
//The powerpoint should be over by this point. Disable the clock now.
p.Close();

我想在powerPoint.WaitForExit()期间运行什么:

private Timer ChangeTime;

//Run SetPos and WhatWeek as soon as the form loads
private void PptxClock_Load(object sender, EventArgs e)
{
UpdateTime();
SetTimer();
}

public void UpdateTime()
{
OverlayTime.Text = "Time: " + DateTime.Now.ToString("h:mm:ss") + ".";
}

//Set the timer
private void SetTimer()
{
    ChangeTime = new Timer
    {
        Enabled = true,
        Interval = 500
    };
    ChangeTime.Tick += new EventHandler(ChangeTime_Tick);
    ChangeTime.Start();
}


//Update the time every tick. We only need the time for this simple form.
//The timer declaration is required to do this.
private void ChangeTime_Tick(object sender, EventArgs e)
{
    OverlayTime.Text = "Time: " + DateTime.Now.ToString("h:mm:ss") + ".";
    Console.WriteLine(DateTime.Now.ToString("h:mm:ss"));

}

我只希望能够更改p表单的时间标签的内容。

0 个答案:

没有答案