我在windows service中写了一句这样的代码,启动.exe
System.Diagnostics.Process.Start(Application.StartupPath + "\\windy.exe");在程序调试的时候,一切都OK。
但是在做成安装包后,安装以后,会出现这样的情况:
在进程管理中windy.exe启动起来了,也出现了winForm,但是我用先程做的一个倒计时label,却无法显示时间,但是如果在label.text中输入一个常量是可以显示的,请问我该怎么样解决这个问题,谢谢!~
System.Diagnostics.Process.Start(Application.StartupPath + "\\windy.exe");在程序调试的时候,一切都OK。
但是在做成安装包后,安装以后,会出现这样的情况:
在进程管理中windy.exe启动起来了,也出现了winForm,但是我用先程做的一个倒计时label,却无法显示时间,但是如果在label.text中输入一个常量是可以显示的,请问我该怎么样解决这个问题,谢谢!~
public frCountDown()
{
//
// Required for Windows Form Designer support
//
InitializeComponent(); //
// TODO: Add any constructor code after InitializeComponent call
//
this.threadStart = new System.Threading.ThreadStart(Application_Tick);
this.thread = new System.Threading.Thread(threadStart);
this.thread.Priority = System.Threading.ThreadPriority.Lowest;
}private void frCountDown_Load(object sender, System.EventArgs e)
{
this.thread.Start();
} public void Application_Tick()
{
this.lblNow.Text = "1111";
string strXMLFilePath = string.Empty;
iCareEye.iCareEyeClassLibrary.OperateXML operatexml = new iCareEye.iCareEyeClassLibrary.OperateXML();
iCareEye.iCareEyeClassLibrary.OperateTime time = new iCareEye.iCareEyeClassLibrary.OperateTime();// strXMLFilePath = "F:" + "\\TaskTime.xml";
strXMLFilePath = System.IO.Directory.GetCurrentDirectory() + "\\TaskTime.xml"; operatexml.LoadXML(strXMLFilePath);
string strTaskTime = operatexml.ReadXML("nextintervaltime") + ":00";
string strNowTime = System.DateTime.Now.ToLongTimeString();
while(!strNowTime.Equals(strTaskTime))
{
this.lblNow.Text = time.MinusSecond(strTaskTime, strNowTime);
System.Threading.Thread.Sleep(1000);
strNowTime = System.DateTime.Now.ToLongTimeString();
}
this.Hide(); frScreenSaver frss = new frScreenSaver();
frss.ShowDialog();
this.Close();
}
我是这样加的:
static void Main()
{
frCountDown fr = new frCountDown();
fr.thread.Start();
Application.Run(new frCountDown());
}
但是时间还是没有显示出来,另外会产生多个进程,并且在main函数里不能用this.thread.start();因为还没有实例化!~
1、在窗体上加一个timer,interval设为30就可以了,enable设为false;
2、在窗体load事件最后,把上面的timer对象的enable设为true;
3、然后在timer相应时间中,去启动线程,注意在此事件一开始的时候,要把timer的enable设为false。
strXMLFilePath = System.IO.Directory.GetCurrentDirectory() + "\\TaskTime.xml";
不能用上面这句话,
必须用strXMLFilePath = Application.StartupPath + "\\TaskTime.xml";如果是单独双击.exe文件是可以用System.IO.Directory.GetCurrentDirectory()这个的,但是要是有其它的.exe文件来启动另一个.exe文件时,要读当前目录必须用Application.StartupPath谢谢大家!^0^