473,378 Members | 1,426 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Is Windows Service what I need?

I have a Form that on a timer uses FTP to update data on
the local disk.

I would like this Form to start on boot of the computer
and stay running still shutdown.

Like putting it in the startup folder?? Or is that old
Windows 98 terminology?

For an XP machine is Windows Service for this purpose? I
read some on another post that Windows Service does not
support Forms?!? Hmmmm?

If so... then how do I integrate my Form code with its
data processing into the Windows Service approach?

Thanks!

Bob
Nov 21 '05 #1
5 1085
"BobAchgill" <an*******@discussions.microsoft.com> wrote in message
news:04****************************@phx.gbl...
I would like this Form to start on boot of the computer
and stay running still shutdown.


Do you really want it running

"Boot 'til shutdown"

or would

"Log-On 'til Log-Off"

do just as well?

If the former, go the Windows Service route.

If the latter, just pop a shortcut into the Startup Group.

HTH,
Phill W.
Nov 21 '05 #2
I think "Boot 'til shutdown". I need to have the
function working regardless of who is logged on.

Though, never did find the "startup group" on my XP Pro.
Where would that be hiding?

So that leaves the question...

Where do I stick in my FTP processing code??

Here is what I see in my Window Service code so far...
where do I put my code?

+++++++++++++++++++++++++++++++++
Protected Overrides Sub OnStart(ByVal args() As String)
' Add code here to start your service. This
method should set things
' in motion so your service can do its work.
End Sub

Protected Overrides Sub OnStop()
' Add code here to perform any tear-down
necessary to stop your service.
End Sub
+++++++++++++++++++++++++++++++++



-----Original Message-----
"BobAchgill" <an*******@discussions.microsoft.com> wrote in messagenews:04****************************@phx.gbl...
I would like this Form to start on boot of the computer
and stay running still shutdown.
Do you really want it running

"Boot 'til shutdown"

or would

"Log-On 'til Log-Off"

do just as well?

If the former, go the Windows Service route.

If the latter, just pop a shortcut into the Startup

Group.
HTH,
Phill W.
.

Nov 21 '05 #3
"BobAchgill" <an*******@discussions.microsoft.com> wrote in message
news:04****************************@phx.gbl...
So that leaves the question...

Where do I stick in my FTP processing code??


OnStart gets called when your service is started and returning from
this method signals to the Service Control Manager that your service
has started successfully. What I'd suggest is a System.Timers.Timer
that fires once and only once that you start in OnStart.

When this timer fires, call your main processing routine that can do
whatever it needs to, but I'd recommend using Thread.Sleep() to
leave a gap in processing; don't use the Timer (I've had them stop
on me for no readily apparent reason).

OnStop gets called when your service is asked to stop and returning
from this method says to the Service Control Manager "you can kill
this one now"; beware if your processing could be interrupted part
way through!

(a starting point)

Private m_bShutDownComplete as Boolean = False
Private m_bShutDownRequested as Boolean = False

Sub OnStart()
Me.tmrStarter.Enabled = True
End Sub

Sub OnStop()
m_bShutDownComplete = False
m_bShutDownRequested = True
Do While m_bShutDownComplete
Thread.Sleep( 500 )
Loop
End Sub

Sub tmrStarter_Elapsed( ... ) _
Handles tmrStarter.Elapsed

Me.tmrStarter = False
RunProcess()

End Sub

Sub RunProcess()
Do While Not m_bShutDownRequested
' Do Something Useful
. . .
Thread.Sleep( 500 ) ' or whatever
Loop
m_bShutDownComplete = True
End Sub

HTH,
Phill W.
Nov 21 '05 #4
Phil,

Thank you so much for clearing up how this Windows
Service stuff works with real code.

What you wrote really looks great.

Once question... why did you start it off with a timer...

Sub OnStart()
Me.tmrStarter.Enabled = True

as opposed to calling the process right off ...

Sub OnStart()
RunProcess()

Bob

-----Original Message-----
"BobAchgill" <an*******@discussions.microsoft.com> wrote in messagenews:04****************************@phx.gbl...
So that leaves the question...

Where do I stick in my FTP processing code??
OnStart gets called when your service is started and

returning fromthis method signals to the Service Control Manager that your servicehas started successfully. What I'd suggest is a System.Timers.Timerthat fires once and only once that you start in OnStart.

When this timer fires, call your main processing routine that can dowhatever it needs to, but I'd recommend using Thread.Sleep() toleave a gap in processing; don't use the Timer (I've had them stopon me for no readily apparent reason).

OnStop gets called when your service is asked to stop and returningfrom this method says to the Service Control Manager "you can killthis one now"; beware if your processing could be interrupted partway through!

(a starting point)

Private m_bShutDownComplete as Boolean = False
Private m_bShutDownRequested as Boolean = False

Sub OnStart()
Me.tmrStarter.Enabled = True
End Sub

Sub OnStop()
m_bShutDownComplete = False
m_bShutDownRequested = True
Do While m_bShutDownComplete
Thread.Sleep( 500 )
Loop
End Sub

Sub tmrStarter_Elapsed( ... ) _
Handles tmrStarter.Elapsed

Me.tmrStarter = False
RunProcess()

End Sub

Sub RunProcess()
Do While Not m_bShutDownRequested
' Do Something Useful
. . .
Thread.Sleep( 500 ) ' or whatever
Loop
m_bShutDownComplete = True
End Sub

HTH,
Phill W.
.

Nov 21 '05 #5
"BobAchgill" <an*******@discussions.microsoft.com> wrote in message
news:0d****************************@phx.gbl...
Once question... why did you start it off with a timer...

Sub OnStart()
Me.tmrStarter.Enabled = True

as opposed to calling the process right off ...

Sub OnStart()
RunProcess()


Imagine starting the Service manually, using Control Panel.

You click "Start".
(Your OnStart routine gets called).
Control Panel puts up its progress bar to say "Starting Service"
and quietly ticks away to itself - and will continue to do so until
either the OnStart routine finishes or 30 seconds goes by, when
it gives up and says "I couldn't start the rotten thing" or words to
that effect).

If your OnStart routine ploughs straight into RunProcess(),
OnStart doesn't "finish" until the Service is stopped! By using
the Timer, your code "side-steps" this Call/Return chain, so
OnStart returns almost immediately and Control Panel sees the
Service as started.

So far, so good.

Then, a few milliseconds later, your Timer fires (just the once)
and the Real Work begins.

HTH,
Phill W.
Nov 21 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Artur Kowalski | last post by:
I have a NotifyIcon in my Windows Service project and I am trying to add a ContextMenu to this NotifyIcon or use some of the mouse events. Everything isn't working. I think so base class of the...
9
by: SP | last post by:
Hi All, I wrote a windows service which is supposed to stop after specified amount of time. I am calling OnStop() after specified time. OnStop() methods executed but I dont see the service...
3
by: Doug Bailey | last post by:
I am trying to control a Windows Service via a Web Service interface. (I am developing in .NET2003) I am using the ServiceController object which allows me to read the state of the services with...
4
by: WinDev | last post by:
We are trying to build a system where we have a Windows Service do some manipulation of data, and then sending the data to a Windows App. I had posted a question of how we should do this and was...
2
by: deko | last post by:
When to use a privileged user thread rather than a windows service? That's the question raised in a previous post . It was suggested that if the service needs to interact with a WinForms app...
7
by: Ahmed Perlom | last post by:
Hi all, I am trying to start a windows application that has a GUI from a Windows service written in .NET 2.0. I have been searching on this for few days now with no avail. When using the...
7
by: torus | last post by:
Is the aspnet account called "aspnet" for all non-English versions of Windows and IIS?
5
by: sonali_reddy123 | last post by:
Hello all, I am trying to develop an application which will run as a windows service. The application should have Normal options available with service like start, stop and pause but along...
41
by: pbd22 | last post by:
Hi. I know my windows service works when i run it in debug mode on my dev machine. It also works in release mode on my dev machine. But, when I move the service to a production server, it...
5
by: dm3281 | last post by:
I'm really starting to hate writing services -- or trying to, anyway. Why do I need to rename my project to the service name? Why do I need to set the "ServiceName" property to my service name?...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.