473,943 Members | 19,191 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Re: Changing an application to a service...


"David" <da*********@yo owhoo.comwrote in message
news:3d******** *************** *******@comcast .com...
>
"Steve Gerrard" <my********@com cast.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 926
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.Star t()
End Sub

Private ServiceShutdown Requested as Boolean = False
Private ServiceShutdown Complete as Boolean = False

Sub tmrStarter_Elap sed( ... )
tmrStarter.Stop ()
Do While ( Not ServiceShutdown Requested )

DoSomethingUsef ul()

' 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
ServiceShutdown Complete = True
End Sub

Sub OnStop()
ServiceShutdown Requested = True
Do While ( Not ServiceShutdown Complete )
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 "DoSomethingUse ful" 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
1278
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 has a virtual directory pointing to server 2 in server 1's IIS. Well, for various reasons I want to point to a new server, I'll call server 3, to host the .NET application. I have tried changing the Network Directory in Internet Service Manager...
5
4027
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 our application. Is there a way to do this dinamically so we dont have to recompile our application each time we change IP or server? Thanks.
1
4708
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 based on a server name passed in, and whether ornot the PDA is in the active sync cradle. IE. If the PDA is in the cradle, use localhost. If the PDA isn'tin the cradle, then allow connection over wi-fi to any validwebservice by changing the computer...
2
5305
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 the web service, without recompiling and redistributing the application?
5
2307
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 a web application and if I need to read the connection string it is reading the connection string from the web.config of web application. I am not knowing how to change the Application domain so that it reads the App.config file instead of...
1
1325
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 dynamic, in the sense the number of users for whom the logging will be turned on may vary from 0 to N from point to point. Though i have couple of solutions to adress this problem i have my concerns about the effiencency. Please advise. Solution 1:...
8
7782
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 automatically creates a virtual directory and configures it. I am using the DirectoryServices.DirectoryEntry class in C# to do this. I am unable to set the .Net version of the virtual directory from 1.1 to version 2. All searches led me to the...
1
5967
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 run the application as a normal windows application, the external assemblies are loaded just fine. When I run the application as a windows service, the application expects the assemblies to be in the windows\system32 directory. How can I change...
3
2903
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 http://localhost/application/en-US, the global.asax is not fired.
0
9970
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
11133
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
11306
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
10669
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...
0
9866
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
8233
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
7395
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
6312
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4914
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.