2014-02-24 30 views
-1

我想运行一个单独的进程,并使用一个dll,这是一个winforms应用程序作为dll。这个问题已经被问过:执行.Net dll

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

既然是已经有一些岁,我想刷新的问题。到目前为止,.Net框架中有没有可用的东西?技术上可行吗?我知道这是用java内,所以我在想,如果净能做到这一点...

感谢

更多信息:这就是我想要的目的。现在有一段代码能够检测我们应用程序中的死锁。检测在另一个阶段明显地运行。因此,如果发生这种情况,我想运行另一个向用户显示对话框的进程,并通知他有关死锁的信息,然后杀死死锁的应用程序。

我想这是一个不同的过程,能够显示一个对话框给用户,因为大部分的时间mainthread将在僵局,如参与。由于gui主线程被阻塞,我无法显示任何内容。

+3

这个答案不是很好吗? http://stackoverflow.com/questions/2822326/a-dll-with-winforms-that-c​​an-be-launched-from-a-main-app – Dayan

回答

0

这已经回答了多次:

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(); 

Code4life

在Solution Explorer中,引用单击鼠标右键,选择Add Reference。这是您添加自定义设计的C#DLL的地方。

现在打开Program.cs文件,并进行以下更改:

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****]); 
     } 
    } 
} 
+0

感谢您的答复。我尝试过,但是当我调试了应该在不同进程中运行的窗体调用时,它与我的应用程序('Process.GetCurrentProcess()。Id')具有相同的Id。还更新了我的问题 – derape