什么会导致编译.exe不执行?

时间:2014-07-29 07:23:11

标签: c# visual-studio-2013

所以我有两个C#程序都引用相同的自定义库。在每个程序中都调用该库中的方法。在一个程序中,此方法调用附加到按钮按下,而另一个程序调用是在Main方法下,因此它应该在执行.exe时运行...除非它没有。当我按下按钮在一个程序中调用方法时,它就像一个魅力,但是在另一个程序的Main方法中的调用没有。

这是我的代码片段:

Windows窗体应用程序中的方法调用(DOES工作)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using p_controller;

/*p_controller is a custom library that contains the static method 
restart_all which restarts some system processes*/

namespace p_restarter_form : Form
{

class p_restart_form
{
   public p_restart_form()
   {
      //constructor does some things in actual program
    }

    private void restart_all_button_Click(object sender, EventArgs e)
    {
       p_controls.restart_all();
    }
 }
}

Windows应用程序的完整代码(不起作用)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using proxy_controller;

namespace p_restarter
{
class p_restart
{
    static void Main()
    {
        p_controls.restart_all();
    }
}
}

因此表单应用程序编译成.exe,当运行时显示带有按钮的表单,当我单击按钮时,调用restart_all()方法并重新启动进程。第二个程序是一个Windows应用程序,它编译成一个.exe,当运行时调用Main()方法,该方法又调用相同的restart_all()方法。

表格有效,Windows应用程序不会......执行时绝对没有。

1 个答案:

答案 0 :(得分:0)

通过代码片段,您很难判断自己在做什么。 似乎在您的Main方法中没有初始化proxy_controls。 第二个片段无法编译。 对于proxy_controls事物应该有一个new的初始化。 或者,如果它是posmon_restart类的类成员,则在Main方法中初始化该类。