Service starting my app too soon?

J

James Blair

I'm relatively new to VB.NET and i was wondering if someone would be
able to help me with a problem that I'm seeing with a service and
application I've created:

The service has two functions: first, on startup, it PROCESS.STARTs
my application (which starts minimized to the system tray as a
notification icon). Second, it watches my app, and restarts it in case
of accidental closing or in the event of a crash.

This process works fine, except for the intial startup at login. At
login I always receive the following error:

EventType : clr20r3 P1 : iam.exe P2 : 3.0.0.0 P3 :
48f4e74d
P4 : mscorlib P5 : 2.0.0.0 P6 : 471ebc5b P7 : 3404
P8 : 15a P9 : system.unauthorizedaccess

After I click OK, the service restarts the application and everything
runs smoothly (until the next logon event).

At first, I was wondering if this was being caused by the application
launching before the desktop and system tray had initialized, but that
really doesnt seem to jive with unauthorizedaccess error, so I can
only assume that the issue is that the app is starting before the user
is fully authenticated (the app writes to a log file on a network
share). Even, that doesnt seem right to me, though, as the error pops
after the login script has processed and the user has mapped their
network drives.

I know I could probably put a sleep event in there, but that's really
clunky. I've thought about putting a new key in HKLM\Software\Micrsoft
\Windows\CurrentVersion\Run to net start the service, but again,
that's far from elegant.

So, does anyone have any thoughts at how I should proceed to
troubleshoot this or a way to get more information about what's really
happening?
 
M

Michael C

James Blair said:
I'm relatively new to VB.NET and i was wondering if someone would be able
to help me with a problem that I'm seeing with a service and application
I've created:
The service has two functions: first, on startup, it PROCESS.STARTs my
application (which starts minimized to the system tray as a notification
icon). Second, it watches my app, and restarts it in case of accidental
closing or in the event of a crash.

A service starts before any users are logged in, that the whole point of a
service, to have something that is always running. So naturally it will try
to start your app before the user is logged in, before network drives are
mapped and before the system tray is created. In fact you're trying to start
your app before the desktop is initialized. Why don't you just start your
app use a registry key as you've suggested and make it impossible to close?
Or, why don't you put the functionality you need into the service itself.

Michael
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top