Cannot evaluate expression because native frame is on top of call stack

I create a simple window service, and when I go for debugging, I get an error: "Unable to evaluate the expression because its own frame is on top of the call stack." Also, when I create a service in Release and start it, it just freezes.

 static void Main()
    {
        ServiceBase[] ServicesToRun;
        ServicesToRun = new ServiceBase[] { new MyService1() };

        ServiceBase.Run(ServicesToRun);
    }

This is all that is in the Program.cs file, where it usually hangs on the ServiceBase.Run line (ServicesToRun).

All that I managed to find relates only to an expression that is not evaluated, because the code is optimized or deals with asp.net and response.redirect.

Code for the service.

    public TruckRateClearService()
    {
        InitializeComponent();
    }

    protected override void OnStart(string[] args)
    {
        tmrProcess.Enabled = true;
    }

    protected override void OnCustomCommand(int command)
    {
        base.OnCustomCommand(command);
        if (command == 129)
        {
            OnStart(null);
        }
    }

    protected override void OnStop()
    {
        tmrProcess.Enabled = false;
    }

    private void tmrProcess_Tick(object sender, EventArgs e)
    {
        tmrProcess.Enabled = false;

        try 
        {
            eventLog.WriteEntry("Clearing Truck Rates Start" + DateTime.Now.ToString());

            TruckRateClearingAgent.Process();

            eventLog.WriteEntry("Clearing Truck Rates Finished" + DateTime.Now.ToString());
        }
        catch (Exception ex)
        {
            eventLog.WriteEntry(ex.ToString(), EventLogEntryType.Error);
        }

        tmrProcess.Enabled = true;
    }

    internal void Run()
    {
        tmrProcess_Tick(tmrProcess, null);
    }

Void Run() . , , .

Native , , 76F17094 ret. , , , - .

, VS, . - .exe, -.vshost.exe. , .exe Attach . - , v4 Framework (.vshost.exe-), - v2 (single.exe) Framework?

, . , , . , , System.Windows.Forms. System.Timers.Timers . VS , , Internal Run(). n.n

+5
3

, .

, . , , .

ServiceBase.OnCustomCommand , .

protected override void OnCustomCommand(int command)
{
   //Debugger.Break()   <- or just put a breakpoint in here.
}

:

c:\>sc control YourServiceName 129
+2

, exe- windows. Windows (SCM). VS, - :

static void Main()
{
    if (Environment.UserInteractive)
    {
        new MyService1().Run();
        Thread.Sleep(Timeout.Infinite);
    }
    else
    {
        ServiceBase.Run(new ServiceBase[] { new MyService1() });
    }
}

MyService1.Run, , . , Run MyService1.Onstart.

SCM, exe VS ( exe VS).

+2

, , , , .NET .

MyService1()? ?

, . .

- :

static void Main(params string[] args)
{
   if (args.Length > 0 && args[0] == "/console")
   {
      // Run whatever your service calls here
   }
   else
   {
      ServiceBase[] ServicesToRun;
      ServicesToRun = new ServiceBase[] { new MyService1() };

      ServiceBase.Run(ServicesToRun);
  }
}

Then, in the project properties on the Debug tab, enter /consolecommand line arguments. You must enter the application and debug it. You can only debug the service by installing it first: http://msdn.microsoft.com/en-us/library/7a50syb3(v=vs.80).aspx

0
source

All Articles