1

I have an asp.net mvc application that spawns a Process as follows:

        Process p = new Process();

        p.EnableRaisingEvents = true;
        p.Exited += new EventHandler(p_Exited);

        p.StartInfo.Arguments = "-interaction=nonstopmode " + inputpath;
        p.StartInfo.WorkingDirectory = dir;

        p.StartInfo.UseShellExecute = false;
        p.StartInfo.FileName = "pdflatex.exe";

        p.StartInfo.LoadUserProfile = true;

        p.Start();
        p.WaitForExit();

Before going further, I need to know whether, e.g., pdflatex.exe is a managed code or a native code?

Edit 1

I need to consider this because: (Hopely I am not wrong...)

  1. Each Asp.net application runs in an separate/isolated AppDomain as opposed to a separate/isolated process.
  2. A native executable cannot live in an AppDomain.

to be continued...

Shortly speaking, I hope my site does not spawn a new process for each request. Because a process is more expensive than an application domain.

Edit 2

My asp.net mvc application allows users to submit LaTeX input commands such as $ax^2+bx+c=0$ to be converted to a pdf file rendering an quadratic equation. Behind the scene, this web app will spawn a process executing pdflatex.exe. The job of pdflatex.exe is converting the LaTeX input commands to pdf document.

Second Person Shooter
  • 14,188
  • 21
  • 90
  • 165
  • What if an unmanaged program hosts the .NET Framework? Do you consider that to be managed or unmanaged? – wj32 Mar 09 '11 at 07:32
  • Looks like a duplicate of http://stackoverflow.com/questions/2638883/how-does-windows-differentiate-between-a-regular-exe-and-a-net-exe – Sanjeevakumar Hiremath Mar 09 '11 at 07:35
  • If you're using `Process.Start()`, guess whether a new process is started? You can't run another executable inside the asp.net AppDomain. – Damien_The_Unbeliever Mar 09 '11 at 07:51
  • @Damien: I think a new process will be created for each `Process.Start` responding each request. Is there any way to solve this issue? – Second Person Shooter Mar 09 '11 at 07:57
  • 1
    @Recycle Bin, you need to tell your actual problem - what you are trying to do by launching the exe? Its simple math - the code that you have shown, will always start new process per invocation. If you invoke it 3 times per request then three processes will launched per request. Whether you can use the same process across request would depend upon the the task that process is supposed to do, how it is achieving it, does it support any IPC mechanism etc. – VinayC Mar 09 '11 at 08:07
  • unless pdflatex has some managed api or wrapper you have to spawn a process each time, but you might consider some cleaning up process service kills pdflatex exe's idle instances. – adt Mar 09 '11 at 08:26
  • @Recycle Bin, don't know much about latex or pdflatex but it boils down to that you have a tool to convert latex input to pdf file. Now, if tool is supposed to be used as command line (as appeared in your case) then it doesn't matter if its native/managed exe - you have to start the process. However, process would be short lived as whenever pdf file is created, the process should get terminated. A better alternative will be to find some library (preferably .NET) that could do the same thing! – VinayC Mar 09 '11 at 08:30
  • @VinayC: If I create a web service wrapping the code above instead of a web application, does the issue still exist? – Second Person Shooter Mar 09 '11 at 09:34
  • @Recycle Bin, it doesn't matter - as such web service is it self an web app (servicing soap over HTTP). – VinayC Mar 09 '11 at 12:59

2 Answers2

0

Not an easy task, but you can look at that library Microsoft.Cci.PeReader.dll Possibly parsing the PE header could point the information you need.

Felice Pollano
  • 32,832
  • 9
  • 75
  • 115
0

Assembly.LoadFile() throws BadImageFormatException when "An attempt is made to load an unmanaged dynamic link library or executable (such as a Windows system DLL) as if it were a .NET Framework assembly." See remarks and example from http://msdn.microsoft.com/en-us/library/system.badimageformatexception.aspx

Second Person Shooter
  • 14,188
  • 21
  • 90
  • 165
Christian
  • 7,433
  • 4
  • 36
  • 61