-1

I want to run a seperate process and use a dll which is a winforms application as dll. This question has already been asked before:

Is it possible to execute a .NET dll without an exe to load it?

Since it is already some years old, I wanted to refresh the question. Is there anything available within the .Net framework by now? Is that technically possible? I know it is within java, so I was wondering if .Net can do that too...

Thanks

Further information: Here is what I'm trying to achieve. Right now there is a piece of code which is able to detect deadlocks within our appplication. The detection is obviosly running in another tread. So if that happens, I want to run another process which shows a dialog to the user and informs him about the deadlock and then kills the deadlocked application.

I want it to be a different process to be able to show a dialog to the user, because most of the time the mainthread will be involved in the deadlock, eg. I have no way to show something since the gui main thread is blocked.

Community
  • 1
  • 1
DerApe
  • 3,097
  • 2
  • 35
  • 55
  • 3
    This answer is not good? http://stackoverflow.com/questions/2822326/a-dll-with-winforms-that-can-be-launched-from-a-main-app – Dayan Feb 24 '14 at 15:04

1 Answers1

0

This has been answered multiple times:

From Killercam:

 // Execute the method from the requested .dll using reflection (System.Reflection).
    Assembly DLL = Assembly.LoadFrom(strDllPath);
    Type classType = DLL.GetType(String.Format("{0}.{0}", strNsCn));
    object classInst = Activator.CreateInstance(classType, paramObj);
    Form dllWinForm = (Form)classInst;  
    dllWinForm.ShowDialog();

From Code4life

In the Solution Explorer, right-click on the References and select Add Reference. This is the point where you add your custom designed C# DLL.

Now open Program.cs, and in make the following change:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using ****your DLL namespace here****
namespace WindowsFormsApplication2
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new [****your startup form (from the DLL) here****]);
        }
    }
}
Community
  • 1
  • 1
Dayan
  • 7,634
  • 11
  • 49
  • 76
  • Thanks for you reply. I tried that but when I debugged the call of the form which is supposed to run in a different process, it had the same Id as my application (`Process.GetCurrentProcess().Id`). Also updated my question – DerApe Feb 24 '14 at 15:28