Windows Service Has Nothing To Do Error

  • Thread starter Thread starter Joseph Bittman MCAD
  • Start date Start date
J

Joseph Bittman MCAD

June 16, 2005

I'm creating a Windows Service that will backup some statistics files
for my web application. I am having a problem when I try to start my
service, where it says something about that the service started and stopped
and sometimes this is caused by the service not having work to do. It
mentioned that the Peformance Logs & Alerts service has this problem....
What I am wanting to do is in OnStart, to create a new thread and then have
that thread continuely (with .Sleep to create intervals) process a method
that backs up my files. When I do this, I don't get the stopped/started
service message, but no code ever gets executed in the method that the
thread runs. When I just try to implement it in the OnStart method itself
and not using another thread, then I get an error about that the service
couldn't be started in a timely fashion. If I implement it in the OnStart
and not have intervals, then I get the nothing to do message.... I am
greatly confused by this and would GREATLY appreciate any help! I'm sure
that I'm doing something wrong that is very obvious, but I haven't been able
to figure out what. Basically, the code looks like:

OnStart Method

dim th as new thread(addressof Backup)
th.start

Backup Method

do while true
dim reader as new streamreader(filepath)
dim writer as new streamwriter(newfilepath)

writer.write(reader.readtoend)
writer.flush
writer.close
reader.close
th.sleep(new timespan(0,5,0))
loop

Any thoughts would be greatly appreciated! Thanks and have a great day!

--
Joseph Bittman
Microsoft Certified Application Developer

Web Site: http://71.35.110.42
Dynamic IP -- Check here for future changes
 
Why are you using 'TimeSpan' in your th.Sleep?

You could just say: 'th.Sleep(500)'

When you close the StreamWriter objects they are not fully distroyed

Any chance of the rest of the code to see?

Where do you get the file/directory paths from?

Crouchie1998
BA (HONS) MCP MCSE
 
Back
Top