473,397 Members | 1,961 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,397 software developers and data experts.

Re: Changing an application to a service...


"David" <da*********@yoowhoo.comwrote in message
news:3d******************************@comcast.com. ..
>
"Steve Gerrard" <my********@comcast.netwrote in message
news:VZ******************************@comcast.com. ..
>David wrote:
>>Hi,

I am trying to change an application to a service and am having a few
problems. Here are the steps I've been performing:

- Exclude all forms from project and delete all associated files.
- Disable use framework (.net application?) in project properties
- Switch application type to Service
- Add a service class to the project
- Add an installer to the service class and configure properties of
components for localservice and automatic startup
- Add a setup project
- Add primary output to setup project
- Set all custom actions to primary output

At this point I receive an error stating that there is no Main
subroutine. I did not have this problem last time I switched an
application to a service, years ago.
...
>>>
How should this program begin running? Through Main() or the
service's OnStart event? Do I need to use both? Can I use both?

I would suggest you start a new project, make it a windows service, and
go from there. I believe the service class has a designer file with it,
and a fairly convoluted bit of code dealing with starting the service. I
would not want to recreate that from scratch. Once you get that template
in place, from your point of view, an instance of your service class is
created for you, and you first get control in the OnStart event.

If you start it that way, you should be able to copy and paste, or copy
files over, to build up the rest of your application in the service.

Thanks Steve,

I'll give that a try.

david

No luck yet. I created a service from scratch but keep getting the "service
on local computer started and then stopped," error. I commented almost all
of the code in my OnStart subroutine yet the error persists. Any ideas why
this might be?

Jun 27 '08 #1
1 907
David wrote:
No luck yet. I created a service from scratch but keep getting the "service
on local computer started and then stopped," error.
Unlike Windows Applications, Services don't keep themselves "alive" all
by themselves. You usually have to code a simple loop construct to keep
the processing "going" otherwise they just get started (by the Service
Controller), call your OnStart routine and then, with nothing else to
do, curl up their toes and die.

I'd recommend a routine with a loop construct and some Sleep() calls,
initiated from a Timer that you start in onStart and that only ever
fires once (this allows OnStart to return quickly so that Service
Controller doesn't get upset that your service "isn't responding").

Sub OnStart()
tmrStarter.Start()
End Sub

Private ServiceShutdownRequested as Boolean = False
Private ServiceShutdownComplete as Boolean = False

Sub tmrStarter_Elapsed( ... )
tmrStarter.Stop()
Do While ( Not ServiceShutdownRequested )

DoSomethingUseful()

' Lots of little sleeps rather than one BIG one
' makes for a more better behaved Service
For i As Integer = 1 To 5
Thread.Sleep( 1000 )
Next
Loop
ServiceShutdownComplete = True
End Sub

Sub OnStop()
ServiceShutdownRequested = True
Do While ( Not ServiceShutdownComplete )
Thread.Sleep( 1000 )
Loop
End Sub
Note the extra bit in OnStop to handle Service "stop" requests cleanly.

As soon as you return from OnStop, the Service Controller will tear down
your Service process, no matter /what/ it's doing. The above construct
should let your "DoSomethingUseful" routine complete before the service
collapses.

HTH,
Phill W.
Jun 27 '08 #2

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

Similar topics

1
by: Rod | last post by:
We have a .NET application which is installed on one machine (let's call it server 2), and we point to it using IIS from another machine (our edge server, which I'll call server 1). So, server 1...
5
by: Carlos Hernandez | last post by:
We have created a webservice, and in out test server everyting works fine, but when we want to move it to our production server, we have ti change IP in the webreference properties, and rebuild...
1
by: Nick via .NET 247 | last post by:
I have a similar problem trying to use web services with awindows form application. I currently use a static web referencein my project. What I am trying to do is to programaticallychange the url...
2
by: bill | last post by:
I understand how to change the URL of a web service at run-time. But, if I am using a web service in a windows application, what is a good way to inform the application of the current location of...
5
by: Sridhar | last post by:
Hi, I have created a project which contains classes to read the data from the database. This project has an App.Config file which contains the SqlConnection String. when this code is called from...
1
by: Bala Nagarajan | last post by:
Hello, I am building a web service application in which i will have to implement logging based on user id. My question is where do i store the user ids? Since the nature of this problem is so...
8
by: Rak | last post by:
I am looking for a way to programatically change the .net version of the virtual directory that I am creating within a aspx page. As part of creating a new customer in my asp.net 2 application, it...
1
by: RMB | last post by:
Environment: VS.Net 2003 FW 1.1 VB.Net I have an application that uses reflection to load external assemblies. The external assemblies reside in the same folder as the application exe. When I...
3
by: thomson | last post by:
Hi All, i do have an website with the URL http://localhost/application/ASEAN-ANZ, Once i hit the application, it goes to the Global.asax. but after that if i tried to change the URL...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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...
0
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...
0
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...

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.