473,657 Members | 2,358 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1101
"BobAchgill " <an*******@disc ussions.microso ft.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*******@disc ussions.microso ft.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*******@disc ussions.microso ft.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.T imer
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_bShutDownComp lete as Boolean = False
Private m_bShutDownRequ ested as Boolean = False

Sub OnStart()
Me.tmrStarter.E nabled = True
End Sub

Sub OnStop()
m_bShutDownComp lete = False
m_bShutDownRequ ested = True
Do While m_bShutDownComp lete
Thread.Sleep( 500 )
Loop
End Sub

Sub tmrStarter_Elap sed( ... ) _
Handles tmrStarter.Elap sed

Me.tmrStarter = False
RunProcess()

End Sub

Sub RunProcess()
Do While Not m_bShutDownRequ ested
' Do Something Useful
. . .
Thread.Sleep( 500 ) ' or whatever
Loop
m_bShutDownComp lete = 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.E nabled = True

as opposed to calling the process right off ...

Sub OnStart()
RunProcess()

Bob

-----Original Message-----
"BobAchgill " <an*******@disc ussions.microso ft.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.T imerthat 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_bShutDownComp lete as Boolean = False
Private m_bShutDownRequ ested as Boolean = False

Sub OnStart()
Me.tmrStarter.E nabled = True
End Sub

Sub OnStop()
m_bShutDownComp lete = False
m_bShutDownRequ ested = True
Do While m_bShutDownComp lete
Thread.Sleep( 500 )
Loop
End Sub

Sub tmrStarter_Elap sed( ... ) _
Handles tmrStarter.Elap sed

Me.tmrStarter = False
RunProcess()

End Sub

Sub RunProcess()
Do While Not m_bShutDownRequ ested
' Do Something Useful
. . .
Thread.Sleep( 500 ) ' or whatever
Loop
m_bShutDownComp lete = True
End Sub

HTH,
Phill W.
.

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

Sub OnStart()
Me.tmrStarter.E nabled = 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
5682
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 service System.ServiceProcess.ServiceBase don't catchWindows messages like mouse or timer messages. Any Idea? Thanks,
9
7252
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 stopping. Please advise how to stop the service. Thanks, SP
3
3684
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 no problems. However, I am not able to start or stop the service unless I go through the process of impersonating an administrative user. (See MSDN KB 306158) Since it appears to be a privilege issue, I set the folders in IIS holding the Web...
4
3991
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 told remoting was the way to go. So I got a client and a server program up and going and from the client I can call a routine in the server program. I can't figure out how to actually send data to the client. At the moment the client calls a...
2
6888
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 (which is the UI used to adjust the actions taken by, and the schedule of the service), then a privileged user thread should be used in the UI - no service required. But... "A windows service enables the creation of long-running executable
7
2394
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 System.Diagnostic.Process object to start the application (i.e Notepad), the new app runs and it is listed on the task manger list, but the GUI doesn't show up in the desktop of the current user. I am aware windows service (either LocalSystem,...
7
1909
by: torus | last post by:
Is the aspnet account called "aspnet" for all non-English versions of Windows and IIS?
5
4254
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 with this I need an option to show the windows application which my service has started as a result of its invokation. So I have written a service control by adding a new project of type
41
11630
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 exits immediately with a start/stop/nothing to do error. What could be wrong?
5
3296
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? Why do I need to set a property within my code to the service name? Are all these required or am I just doing this for consistency purposes?
0
8323
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8838
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8739
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8513
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8613
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6176
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5638
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1969
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.