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

My NT Services crash at startup (1 out of 10 time)

P: n/a
On all my Windows Services (written in C# and for some of them in MC++), I
got from time to time crashes at startup (1 out of 10 startup). It occurs
really at the time I click on the "Start service" button.

I have try/catch sections all around, and also have defined an
"UnhandledExceptionEventHandler" in the ctor of the Service Main().
I'm still not able to catch what is going on :-((

The error is:
The instruction at "0x791cfea1" referenced memory at "0x00000050". The memory could not be "read".Click on Ok to Terminate
Click on Cancel to Debug

I do suspect that this may occurs in one of my common assemblies. Probably
in some static member/class initializations.
What I did is to try to place suspect static initializations in a class
initializer and place them within a try/catch sections.

I tried to start the service as a normal program (according to description
shown in MSDN). However, it works ok this way.
Here are my questions:

- If I place a try/catch section in a class initializer, will the catch be
hit in case of problem?
- How could I point out to the location where the problem occured using the
error message shown
- Is it possible to debug the application?
If I press Cancel, DrWatson generates a log. I would like to run JIT
debugger instead
Any help greatly appreciated!!!
Josť

Nov 15 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
Some ideas:

You could put some EventLog.WriteEntry entries in your common assemblies just to try and pinpoint the problem.
Also, make sure that none of your common assemblies inadvertently does any UI.
Verify this by setting the service to 'Allow interaction with desktop' and running the service.

Also; there was a bug in v1.0 of the framework, not sure if it's in v1.1, where services couldn't start if
the eventlog is full. Try clearing the eventlog and see if it helps.

--
Robert Jeppesen
robert.jeppesen%at%durius-dot-se
"Josť Joye" <jo*******@KILLTHESPAMSbluewin.ch> wrote in message news:ud**************@tk2msftngp13.phx.gbl...
On all my Windows Services (written in C# and for some of them in MC++), I
got from time to time crashes at startup (1 out of 10 startup). It occurs
really at the time I click on the "Start service" button.

I have try/catch sections all around, and also have defined an
"UnhandledExceptionEventHandler" in the ctor of the Service Main().
I'm still not able to catch what is going on :-((

The error is:
The instruction at "0x791cfea1" referenced memory at "0x00000050". The memory could not be "read".Click on Ok to Terminate
Click on Cancel to Debug

I do suspect that this may occurs in one of my common assemblies. Probably
in some static member/class initializations.
What I did is to try to place suspect static initializations in a class
initializer and place them within a try/catch sections.

I tried to start the service as a normal program (according to description
shown in MSDN). However, it works ok this way.
Here are my questions:

- If I place a try/catch section in a class initializer, will the catch be
hit in case of problem?
- How could I point out to the location where the problem occured using the
error message shown
- Is it possible to debug the application?
If I press Cancel, DrWatson generates a log. I would like to run JIT
debugger instead
Any help greatly appreciated!!!
Josť

Nov 15 '05 #2

P: n/a
Thanks for the tips.

Sorry for information I missed:

- I currently write into the EventLog as fallback in my tracing routines.
- I already allowed interaction with the Desktop to see if I can get extra
info
- I have set the overwrite eventlog flag (so it will not get full).

Thanks anyway!
Josť

"Robert Jeppesen" <robert.jeppesen(#)durius.se> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Some ideas:

You could put some EventLog.WriteEntry entries in your common assemblies just to try and pinpoint the problem. Also, make sure that none of your common assemblies inadvertently does any UI. Verify this by setting the service to 'Allow interaction with desktop' and running the service.
Also; there was a bug in v1.0 of the framework, not sure if it's in v1.1, where services couldn't start if the eventlog is full. Try clearing the eventlog and see if it helps.

--
Robert Jeppesen
robert.jeppesen%at%durius-dot-se
"Josť Joye" <jo*******@KILLTHESPAMSbluewin.ch> wrote in message

news:ud**************@tk2msftngp13.phx.gbl...
On all my Windows Services (written in C# and for some of them in MC++), I got from time to time crashes at startup (1 out of 10 startup). It occurs really at the time I click on the "Start service" button.

I have try/catch sections all around, and also have defined an
"UnhandledExceptionEventHandler" in the ctor of the Service Main().
I'm still not able to catch what is going on :-((

The error is:
>The instruction at "0x791cfea1" referenced memory at "0x00000050". The

memory could not be "read".
>Click on Ok to Terminate
>Click on Cancel to Debug

I do suspect that this may occurs in one of my common assemblies. Probably in some static member/class initializations.
What I did is to try to place suspect static initializations in a class
initializer and place them within a try/catch sections.

I tried to start the service as a normal program (according to description shown in MSDN). However, it works ok this way.
Here are my questions:

- If I place a try/catch section in a class initializer, will the catch be hit in case of problem?
- How could I point out to the location where the problem occured using the error message shown
- Is it possible to debug the application?
If I press Cancel, DrWatson generates a log. I would like to run JIT
debugger instead
Any help greatly appreciated!!!
Josť


Nov 15 '05 #3

P: n/a
You can attach to the process from within Visual Studio. It's in the debug menu.
Since your service causes a crash in the constructor, start the constructor with
a Thread.Sleep(15000); This will give you time to attach to the process before it crashes.
Also, if the service crashes within 15 seconds, you'll know that it''s probably an initialization in
a variable declaration that is crashing, because such initializasions get compiled in the start of the constructor.

--
Robert Jeppesen
robert.jeppesen%at%durius-dot-se
"Josť Joye" <jo*******@KILLTHESPAMSbluewin.ch> wrote in message news:%2***************@TK2MSFTNGP10.phx.gbl...
Thanks for the tips.

Sorry for information I missed:

- I currently write into the EventLog as fallback in my tracing routines.
- I already allowed interaction with the Desktop to see if I can get extra
info
- I have set the overwrite eventlog flag (so it will not get full).

Thanks anyway!
Josť

"Robert Jeppesen" <robert.jeppesen(#)durius.se> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Some ideas:

You could put some EventLog.WriteEntry entries in your common assemblies

just to try and pinpoint the problem.
Also, make sure that none of your common assemblies inadvertently does any

UI.
Verify this by setting the service to 'Allow interaction with desktop' and

running the service.

Also; there was a bug in v1.0 of the framework, not sure if it's in v1.1,

where services couldn't start if
the eventlog is full. Try clearing the eventlog and see if it helps.

--
Robert Jeppesen
robert.jeppesen%at%durius-dot-se
"Josť Joye" <jo*******@KILLTHESPAMSbluewin.ch> wrote in message

news:ud**************@tk2msftngp13.phx.gbl...
On all my Windows Services (written in C# and for some of them in MC++), I got from time to time crashes at startup (1 out of 10 startup). It occurs really at the time I click on the "Start service" button.

I have try/catch sections all around, and also have defined an
"UnhandledExceptionEventHandler" in the ctor of the Service Main().
I'm still not able to catch what is going on :-((

The error is:
>>The instruction at "0x791cfea1" referenced memory at "0x00000050". The
memory could not be "read".
>>Click on Ok to Terminate
>>Click on Cancel to Debug
I do suspect that this may occurs in one of my common assemblies. Probably in some static member/class initializations.
What I did is to try to place suspect static initializations in a class
initializer and place them within a try/catch sections.

I tried to start the service as a normal program (according to description shown in MSDN). However, it works ok this way.
Here are my questions:

- If I place a try/catch section in a class initializer, will the catch be hit in case of problem?
- How could I point out to the location where the problem occured using the error message shown
- Is it possible to debug the application?
If I press Cancel, DrWatson generates a log. I would like to run JIT
debugger instead
Any help greatly appreciated!!!
Josť



Nov 15 '05 #4

P: n/a
Josť Joye wrote:
On all my Windows Services (written in C# and for some of them in MC++), I
got from time to time crashes at startup (1 out of 10 startup). It occurs
really at the time I click on the "Start service" button.

I have try/catch sections all around, and also have defined an
"UnhandledExceptionEventHandler" in the ctor of the Service Main().
I'm still not able to catch what is going on :-((

The error is:
The instruction at "0x791cfea1" referenced memory at "0x00000050". The
memory could not be "read".
Click on Ok to Terminate
Click on Cancel to Debug


You may have a bad memory module also. Does this happen on only one
computer or on a number of them?
Nov 15 '05 #5

P: n/a
Hello,

This happens on high speed (4 CPUs) computers. I really suspect
initialization problem.

Josť

"James Black" <jb****@ieee.org> wrote in message
news:eB**************@TK2MSFTNGP12.phx.gbl...
Josť Joye wrote:
On all my Windows Services (written in C# and for some of them in MC++), I got from time to time crashes at startup (1 out of 10 startup). It occurs really at the time I click on the "Start service" button.

I have try/catch sections all around, and also have defined an
"UnhandledExceptionEventHandler" in the ctor of the Service Main().
I'm still not able to catch what is going on :-((

The error is:
The instruction at "0x791cfea1" referenced memory at "0x00000050". The


memory could not be "read".
Click on Ok to Terminate
Click on Cancel to Debug


You may have a bad memory module also. Does this happen on only one
computer or on a number of them?

Nov 15 '05 #6

P: n/a
Josť Joye wrote:
Hello,

This happens on high speed (4 CPUs) computers. I really suspect
initialization problem.


This code snippet may help you out. I use this to be able to switch
from running as a service to running the application in a debugger.
Obviously 'runasService' is a boolean type.
By running it in a debugger you may be able to figure out what is
going on.

// The main entry point for the process
static void Main(String[] args)
{
// Creates an instance of the methods that will handle the exception.
//CustomExceptionHandler eh = new CustomExceptionHandler();

// Adds the event handler to to the event.
//Application.ThreadException += new
ThreadExceptionEventHandler(eh.OnThreadException);

if (runAsService)
{
System.ServiceProcess.ServiceBase[] ServicesToRun;

// More than one user Service may run within the same process. To add
// another service to this process, change the following line to
// create a second service object. For example,
//
// ServicesToRun = New System.ServiceProcess.ServiceBase[] {new
Service1(), new MySecondUserService()};
//
ServicesToRun = new System.ServiceProcess.ServiceBase[] { new
LabLoginService() };

System.ServiceProcess.ServiceBase.Run(ServicesToRu n);
}
else
{
LabLoginService service = new LabLoginService();
service.OnStart(args);
}
}

Nov 15 '05 #7

P: n/a
Thanks,

I will try it

Josť
"James Black" <jb****@ieee.org> wrote in message
news:OB****************@TK2MSFTNGP12.phx.gbl...
Josť Joye wrote:
Hello,

This happens on high speed (4 CPUs) computers. I really suspect
initialization problem.


This code snippet may help you out. I use this to be able to switch
from running as a service to running the application in a debugger.
Obviously 'runasService' is a boolean type.
By running it in a debugger you may be able to figure out what is
going on.

// The main entry point for the process
static void Main(String[] args)
{
// Creates an instance of the methods that will handle the exception.
//CustomExceptionHandler eh = new CustomExceptionHandler();

// Adds the event handler to to the event.
//Application.ThreadException += new
ThreadExceptionEventHandler(eh.OnThreadException);

if (runAsService)
{
System.ServiceProcess.ServiceBase[] ServicesToRun;

// More than one user Service may run within the same process. To add
// another service to this process, change the following line to
// create a second service object. For example,
//
// ServicesToRun = New System.ServiceProcess.ServiceBase[] {new
Service1(), new MySecondUserService()};
//
ServicesToRun = new System.ServiceProcess.ServiceBase[] { new
LabLoginService() };

System.ServiceProcess.ServiceBase.Run(ServicesToRu n);
}
else
{
LabLoginService service = new LabLoginService();
service.OnStart(args);
}
}

Nov 15 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.