Starting process from ASP.NET application

  • Thread starter Holger (David) Wagner
  • Start date
H

Holger (David) Wagner

I'm trying to start a process from an ASP.NET Web application. The
reason I need this is to encapsulate a (unmanaged) DLL that sometimes
crashes. If I run this DLL directly with P/Invoke from within my ASP.NET
application, this sometimes crashes the whole IIS.

So the idea is to have a separate server which accepts requests (via a
socket connection), calls the DLL with the given parameters and returns
the results.

This works well when I start the server from a console, but it needs to
be started automatically from the Web application. Currently, I'm doing
it this way:

Process serverProcess;

Int32 port = 13000;
String server = "127.0.0.1";
for (int i=0; i < 3 && client == null; i++) {
try {
client = new TcpClient(server, port);
} catch (SocketException e) {
// probably, the server is not running, so start it now!
if (serverProcess != null) {
serverProcess.Kill();
serverProcess = null;
}
serverProcess = new Process();
serverProcess.StartInfo.FileName = exePath;
serverProcess.StartInfo.Arguments = "127.0.0.1 13000";
serverProcess.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
serverProcess.Start();
}
}

But this "serverProcess.Start()" doesn't work :-(

I get an error dialog "JIT Debugging", "JIT Debugging failed with the
following error: Zugriff verweigert (access denied)", "JIT Debugging was
initiated by the user account "\myMachine\ASPNET". I have added ASPNET
to the Debugger Users group - but that doesn't seem to change anything.

I've also tried it with ProcessWindowStyle.Hidden - but that doesn't
improve things either...

Any ideas how to solve this?

kind regards,
david
 
A

Alvin Bruney [MVP]

If you are running IIS v6, you should put this application in its own
application pool. However if you are not running IIS6 then you will need to
create an appdomain in your code so that your code can run inside the app
domain. An errant program will explode inside the appdomain and not take
down the appserver. With IIS5, it is still possible to crash the appserver
by the way.

Since the exception is coming from the unmanaged world, you will need to
wrap a try/catch block, that is, no parameters like catch {}

You are missing some stuff in your code. Here is the complete code to spawn
a process
Modify your code and see if this helps.

ProcessStartInfo psi = new ProcessStartInfo("notepad.exe");
psi.WindowStyle = ProcessWindowStyle.Hidden;

Process p = new Process();
p.EnableRaisingEvents = true;
p.Exited += new EventHandler(MyExited);
p.StartInfo = psi;
p.Start();

..... do stuff ...

p.Kill(); // Try killing the process

private void MyExited(object sender, EventArgs e)
{
MessageBox.Show("Exited process");
}

This will run notepad "hidden" (for illustration purposes).. Then p.Kill();
should kill it.
 

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

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,810
Latest member
Kassie0918

Latest Threads

Top