Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / July 2006

Tip: Looking for answers? Try searching our database.

Windows service timeout

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
oscar.acostamontesde@googlemail.com - 18 Jul 2006 10:49 GMT
Hello everybody. I'm currently developing a windows service. In OnStart
a launch two threads that carry on some work while the service is
running. My problem comes from the fact that once the service is
installed, it just time out at system startup and don't start. But i'm
able to start it manually once i'm logged in. I read in a page
something about signed assemblyes, saying that clr have to verify the
executable at startup, causing the delay. I just unsigned the assembly
and still face the same problem. I also notice that some compilation of
the solution start at system starup, and othes does not, with out
aparent reason, because there is no code change. Any sugestion? Here is
my code for OnStart method.

/// <summary>
       /// Method launched on service start.
       /// </summary>
       /// <param name="args">none</param>
       protected override void OnStart(string[] args) {
           ThreadPool.QueueUserWorkItem(new WaitCallback(JobWs),
null);
           ThreadPool.QueueUserWorkItem(new
WaitCallback(JobManteinance), null);
           //// Write info to eventlog, so controler detects the
service start.
           eventLog.WriteEntry("Service started",
EventLogEntryType.Information);
       }

JobWs and JobManteinance are two functions that do all the work.
Thanks in advance.
Phil Wilson - 18 Jul 2006 20:18 GMT
There's a general question about how you are installing the service and how
you are starting it. For example, it has a dependency on the Eventlog
service, so there's a chance it will fail when it starts up after a reboot
unless it's configured to be dependent on the Event Log service. There may
be other services it's dependent on (such as RPC). You're probably crashing
in OnStart and you time out because you never return properly from it.

Your model isn't one I'd use. OnStart is like an event that lets you do some
initialization. It's typically not the place to start threads that do all
the work on the service, IMO.  Usually the Main method is where you use
System.ServiceProcess.ServiceBase to call run on an instance of your service
class. You should also worry about putting something in OnStop to shut down
your threads in an orderly manner.

Signature

Phil Wilson [MVP Windows Installer]
----

> Hello everybody. I'm currently developing a windows service. In OnStart
> a launch two threads that carry on some work while the service is
[quoted text clipped - 25 lines]
> JobWs and JobManteinance are two functions that do all the work.
> Thanks in advance.
oscar.acostamontesde@googlemail.com - 19 Jul 2006 11:16 GMT
Hello Phil, thanks for your answer. So, you suggest that I only shoul
initialize variables in OnStart method? And how do I start the threads
then? Could you provide some code example of the model you talk about?
Another question is: If i do my service dependant on other, windows
will launch first the necesary services before launching mine?
It is the first windows service i write and in the examples i saw in
internet people usually start the threads in OnStart event. I'm also
overwriting the OnStop event handler, an there I stop the threads I
launched. As they are not cooperating in any way, it's not important
the order. Any help would be apreciated. Thanks again.

Oscar Acosta

> There's a general question about how you are installing the service and how
> you are starting it. For example, it has a dependency on the Eventlog
[quoted text clipped - 42 lines]
> > JobWs and JobManteinance are two functions that do all the work.
> > Thanks in advance.
Phil Wilson - 19 Jul 2006 20:52 GMT
If you set up the dependencies correctly then yes, your service will start
after the event log service has started.

There are always lots of ways to do something, but this is the general model
for services that I prefer:
http://www.codeproject.com/csharp/cron.asp

where a thread belonging to the class is started in OnStart and stopped in
OnStop, and the thread runs some method you implement. However it's cleaner
to use a ManualResetEvent that the thread checks periodically so that it can
shut down cleanly, rather than Thread.Abort used there. Your ThreadPool
doesn't seem to deal with the case where the service gets stopped (how do
you shut down the threads etc).  So you might get into some issues when you
try to stop your service unless you deal with that. However I suspect your
crashing problem at boot time is your dependency on the event log service.
Signature

Phil Wilson [MVP Windows Installer]
----

> Hello Phil, thanks for your answer. So, you suggest that I only shoul
> initialize variables in OnStart method? And how do I start the threads
[quoted text clipped - 62 lines]
>> > JobWs and JobManteinance are two functions that do all the work.
>> > Thanks in advance.
oscar.acostamontesde@googlemail.com - 20 Jul 2006 12:59 GMT
Hello Phil. Thanks a lot, you were completely rigth about it, I added
the dependency and the service now starts fine!
I was using the ThreadPool because I was getting mad about the reason
for the service not starting. So I thougt
that maybe the overhead caused by the new threads were the problem, and
I decided to use the threadpool thinking that maybe as those threads
were already created by the framework i could win some miliseconds ;)
Thanks a lot again!
Oscar Acosta

> If you set up the dependencies correctly then yes, your service will start
> after the event log service has started.
[quoted text clipped - 80 lines]
> >> > JobWs and JobManteinance are two functions that do all the work.
> >> > Thanks in advance.
oscar.acostamontesde@googlemail.com - 21 Jul 2006 11:15 GMT
Hello again. I have one more question. Is there any way to know all the
services that mine depends on?
Thanks,

Oscar Acosta

> If you set up the dependencies correctly then yes, your service will start
> after the event log service has started.
[quoted text clipped - 80 lines]
> >> > JobWs and JobManteinance are two functions that do all the work.
> >> > Thanks in advance.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.