5

I'm testing a trivial web role under Azure Compute Emulator and have overridden OnStart(), Run() and OnStop() methods in my class that derives from RoleEntryPoint.

OnStart() and Run() are called but OnStop() is not - I will either press "Stop debugging" in Visual Studio or close the browser window and the role will be terminated, but OnStop() is never called. I've checked - the override keyword is present in OnStop() definition.

That's not very convenient - it means I can't test my OnStop() outside a live cloud.

Can I somehow make Compute Emulator call OnStop() in my role?

sharptooth
  • 167,383
  • 100
  • 513
  • 979

3 Answers3

6

I suspect (but I'm not sure), that if you open the compute emulator UI and "stop" the deployment there, OnStop() should be called.

user94559
  • 59,196
  • 6
  • 103
  • 103
  • 1
    This no longer works. Calling RoleEnvironment.RequestRecycle(); works – RickAndMSFT Nov 18 '12 at 22:36
  • 1
    As far as I can tell this is working again, though the options are "Suspend" or "Restart" now in the emulator UI. – user1454265 Apr 23 '15 at 20:02
  • Far from perfect design decision. If VS can indicate to fabric to abort when VS debugger is stopping, emulator should raise OnStop... if you happen to spawn off processes in your role, those will not be terminated and become ghosts. – Sean Feldman May 27 '15 at 06:11
2

You can use csrun to update the configuration of a running deployment. When you give the command the instance will call the OnStop() method.

To update the ServiceConfigure:

  • Open the Azure SDK bin folder through the command line
  • Issue the command csrun.exe /update:{Deployment ID, just the number};{Path of the cscfg file}

In my Compute Emulator it would be:

  • csrun.exe /update:252;"D:\user\My Documents\Visual Studio 2010\Projects\CSM\CSC\bin\Debug\ServiceConfiguration.cscfg"
ToinoBiclas
  • 262
  • 4
  • 13
1

If you intentionally exit from the Run() method, I believe OnStop() should be called.

dunnry
  • 6,858
  • 1
  • 20
  • 20