Click here to Skip to main content
15,888,454 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
C#
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");
	}
}

Any wise answers for me? Threads and Dates are new to me.
Thanks.
Download linky:
http://www.mediafire.com/?n72i2wp54qd11cv
Or click here...
Posted
Updated 9-Feb-11 22:52pm
v4
Comments
Sunasara Imdadhusen 10-Feb-11 4:10am    
You need to execute your EXE in silent mode?
M Bester 10-Feb-11 4:54am    
I need it to display a window, I tried
prcReminder.StartInfo.CreateNoWindow=false;
but it still didnt show a window.

Simples:
Change
C#
dtmNext.AddDays(1);

to
C#
dtmNext = dtmNext.AddDays(1);
 
Share this answer
 
Comments
M Bester 10-Feb-11 4:18am    
Brilliant! Thanks it works, now I just need to make the program visible.
Sergey Alexandrovich Kryukov 10-Feb-11 11:13am    
As simple as that.
--SA
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.
 
Share this answer
 
Comments
Espen Harlinn 10-Feb-11 16:21pm    
That's right - he will also have to get the handle of the logged on window station, and set that as the active window station for his application - my 5
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"
 
Share this answer
 
You real problem is poor exception handling.
Please pardon me if it was only for reporting a problem, but in real life you do it right.
I thinks good advice wouldn't hurt.

So, you need to catch all exceptions at the very top on the stack of every thread. It looks like you do. But now, you need to use your exception information from Exception e which is present in your code. Your sample should give you warning for not using the variable e. You need to collect all exception information, including the Stack and all inner exceptions, recursively. Then, you need to use system log to log all information there.

It will also help you to post well-posed problems as CodeProject Questions!

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900