线程/日期时间错误,永不停止(Windows Service) [英] Thread/DateTime error, never stops (Windows Service)

查看:98
本文介绍了线程/日期时间错误,永不停止(Windows Service)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Windows服务有点问题.终于使它工作,运行我的外部程序,等等.但是只要线程在10秒后唤醒,它就会继续运行,并且不显示窗口,仅在任务管理器中显示.

Hi, having a bit of a problem with my windows service. Finally got it to a working condition, running my external program, etc. but it keeps running it whenever the thread wakes up after 10 seconds and it doesn''t show the window, only shows in Task manager.

protected void ProcessProc()
{
	try
	{
		WriteToFile("Running ProcessProc: " + intRuntime.ToString());
		prcReminder.StartInfo.UseShellExecute=false;
		prcReminder.StartInfo.FileName=(@"C:\PortionPopUp\Reminder.NET.exe");
                //prcReminder.StartInfo.CreateNoWindow=false; //Didnt show a window
		prcReminder.Start();
		intRuntime++;
	}
	catch(Exception e)
	{
		WriteToFile("Error in: ProcessProc");
	}
}
		
protected void ThreadProc()
{
	try
	{
		WriteToFile("ThreadProc starting...");
		DateTime dtmTemp = DateTime.Now;
		DateTime dtmNext = new DateTime(dtmTemp.Year, dtmTemp.Month, dtmTemp.Day, 10, 57, 00);
		while (true)
		{
			DateTime dtmCurrent = DateTime.Now;
			if(dtmCurrent >= dtmNext)
			{
				ProcessProc();
				dtmNext.AddDays(1);
				WriteToFile("Running: Reminder.NET.exe");
			}
			Thread.Sleep(10000);
		}
	}
	catch(Exception e)
	{
		WriteToFile("Error in: ThreadProc");
	}
}


有什么明智的答案吗?线程和日期对我来说是新的.
谢谢.
下载链接:
http://www.mediafire.com/?n72i2wp54qd11cv
或单击此处...


Any wise answers for me? Threads and Dates are new to me.
Thanks.
Download linky:
http://www.mediafire.com/?n72i2wp54qd11cv
Or click here...

推荐答案

简单:
更改
Simples:
Change
dtmNext.AddDays(1);




to

dtmNext = dtmNext.AddDays(1);


修复了异常,这可能有助于使UI正常工作.

为了使您的程序可见,您必须确保已使用允许服务与桌面交互"选项安装并配置了服务.您可以在登录"选项卡下已安装服务的配置对话框中找到它.为了使用此功能,该服务必须在本地系统帐户下运行.
Since you have the exceptions fixed, this might help in getting your UI to work.

To make your program visible, you will have to ensure that your service is installed and configured with the "Allow service to interact with desktop" option. You can find this in the configuration dialog for the installed service under the Log On tab. In order to use this, however, the service will have to run under the Local System account.


您使用的是哪个Windows版本?如果您使用的是Windows Vista或更高版本,则新的会话0隔离可能会阻止您的Windows正在显示...

确保打开任务管理器,转到进程"选项卡并添加会话ID"列以显示您的服务正在运行的会话.

http://www.CoreTechnologies.com
"Windows服务专家"
What version of Windows are you using? If you are on Windows Vista or later, the new Session 0 Isolation may be preventing your Windows from being shown...

Be sure to open the Task Manager, go to the Processes tab and add the "Session ID" column to show the session where your service is running.

http://www.CoreTechnologies.com
"Experts in Windows Services"


这篇关于线程/日期时间错误,永不停止(Windows Service)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆