By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,876 Members | 1,191 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,876 IT Pros & Developers. It's quick & easy.

thread won't start on server

P: n/a
Hi,

I've got a Windows-service that runs nice and smooth on my local
machine, but when installed on a server it fails to start the thread
inside. I can't figure out what's wrong.
The code below executes as it should on my machine: test123 is written
to the eventlog, but it's not on the server where it should be
installed.
It has however run for a few days on the server, but just stopped one
day (perhaps after a reboot?). The eventlog isn't showing any error
messages either - the OnStart method is executed just fine (tested that
also by writing to the eventlog). Only the mythread function doesn't
get started anymore... Does anyone have any idea how that's possible?

Thanks in advance!

using System.Diagnostics;
using System.Threading;

namespace mynamespace
{
public class myservice: System.ServiceProcess.ServiceBase
{
...
protected override void OnStart(string[] args)
{
ThreadStart ts = new ThreadStart(mythread);
Thread t = new Thread(ts);
t .Start();
}

public void mythread()
{
EventLog.WriteEntry("test123");
try
{
...
}
catch(ThreadAbortException)
{
}
}
...
}
}

Jan 16 '06 #1
Share this Question
Share on Google+
8 Replies


P: n/a
sir dd wrote:
I've got a Windows-service that runs nice and smooth on my local
machine, but when installed on a server it fails to start the thread
inside. I can't figure out what's wrong.
The code below executes as it should on my machine: test123 is written
to the eventlog, but it's not on the server where it should be
installed.
It has however run for a few days on the server, but just stopped one
day (perhaps after a reboot?). The eventlog isn't showing any error
messages either - the OnStart method is executed just fine (tested that
also by writing to the eventlog). Only the mythread function doesn't
get started anymore... Does anyone have any idea how that's possible?


If you put a call to EventLog.WriteEntry in your OnStart method, does
that appear in the event log?

Jon

Jan 16 '06 #2

P: n/a
Yes it does. Both on my development machine and on the server.

Jan 16 '06 #3

P: n/a
sir dd wrote:
Yes it does. Both on my development machine and on the server.


So if you put two logging lines, one before the call to Thread.Start
and one after, they both get executed - but the logging line at the
very start of the new thread *doesn't* get called, right?

Hmm. That sounds very odd indeed. I'll have a think about it...

Jon

Jan 16 '06 #4

P: n/a

"sir dd" <dd*******@hotmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
| Hi,
|
| I've got a Windows-service that runs nice and smooth on my local
| machine, but when installed on a server it fails to start the thread
| inside. I can't figure out what's wrong.
| The code below executes as it should on my machine: test123 is written
| to the eventlog, but it's not on the server where it should be
| installed.
| It has however run for a few days on the server, but just stopped one
| day (perhaps after a reboot?). The eventlog isn't showing any error
| messages either - the OnStart method is executed just fine (tested that
| also by writing to the eventlog). Only the mythread function doesn't
| get started anymore... Does anyone have any idea how that's possible?
|
| Thanks in advance!
|
|
|
| using System.Diagnostics;
| using System.Threading;
|
| namespace mynamespace
| {
| public class myservice: System.ServiceProcess.ServiceBase
| {
| ...
| protected override void OnStart(string[] args)
| {
| ThreadStart ts = new ThreadStart(mythread);
| Thread t = new Thread(ts);
| t .Start();
| }
|
| public void mythread()
| {
| EventLog.WriteEntry("test123");
| try
| {
| ...
| }
| catch(ThreadAbortException)
| {
| }
| }
| ...
| }
| }
|

This:
| t .Start();
| }

wouldn't actually compile so I guess this is not your real code. Could you
post the actual OnStart and myThread methods?

Willy.
Jan 16 '06 #5

P: n/a
Hi,

I've cut out some parts, because I can't post business critical code,
sorry!

protected override void OnStart(string[] args)
{
ThreadStart ts = new ThreadStart(threadlogrotation);
thrLogRotate = new Thread(ts);
thrLogRotate.Start();
}

public void threadlogrotation()
{
EventLog.WriteEntry("test123");
try
{
}
catch(ThreadAbortException)
{
}
catch(Exception err)
{
}
}

Jan 17 '06 #6

P: n/a
sir dd wrote:
I've cut out some parts, because I can't post business critical code,
sorry!


That doesn't matter - but does the code you've posted demonstrate the
problem? If you deploy that code, does the same thing happen? We need
to see code which definitely exhibits the problem, showing everything
it can (such as that OnStart is definitely being called, and that the
code definitely reaches the end of it, and that it can write to the
event log).

Jon

Jan 17 '06 #7

P: n/a

"sir dd" <dd*******@hotmail.com> wrote in message
news:11*********************@g43g2000cwa.googlegro ups.com...
| Hi,
|
| I've cut out some parts, because I can't post business critical code,
| sorry!
|
| protected override void OnStart(string[] args)
| {
| ThreadStart ts = new ThreadStart(threadlogrotation);
| thrLogRotate = new Thread(ts);
| thrLogRotate.Start();
| }
|
| public void threadlogrotation()
| {
| EventLog.WriteEntry("test123");
| try
| {
| }
| catch(ThreadAbortException)
| {
| }
| catch(Exception err)
| {
| }
| }
|

No problem as long as you don't cut anything in OnStart or before your
WriteEntry in your thread procedure.

What's the status of your service after you start it with the "Services"
control panel applet?

What if you do this?

thrLogRotate.Start();
Thread.Sleep(100);
EventLog.WriteEntry("Started");
}

Willy.

Jan 17 '06 #8

P: n/a
I install the service via InstallUtil.exe and always start it manually
through Control Panel - Administrative Tools - Services.
That works fine and does not throw any errors.
I can also stop the service like it should be stopped.

Only the thread-method does not get executed.
WriteEntry in the thread-method does not write anything to the
EventLog, but it does in the OnStart method.

I'm now going to build a completely new project with a clean service
with only a WriteEntry call in the thread-method. But even if that
should work, it still not explains why my perfectly good service just
stopped working one day...

Thanks guys!

Jan 23 '06 #9

This discussion thread is closed

Replies have been disabled for this discussion.