开发者

Can I ask Azure runtime to not restart my role if OnStart() throws an exception?

开发者 https://www.devze.com 2023-03-19 19:55 出处:网络
My Azure web role currently contains lots of bugs and throws exceptions from OnStart(). Once an exception is开发者_Python百科 thrown Azure runtime starts the role again. That\'s not convenient for me

My Azure web role currently contains lots of bugs and throws exceptions from OnStart(). Once an exception is开发者_Python百科 thrown Azure runtime starts the role again. That's not convenient for me - the role OnStart() runs to exactly the same point and crashes again and this continues forever. I'd rather have it stopped once it crashes.

Can I somehow ask Azure runtime to not restart my role once OnStart() crashes with an exception?


Well, you can put a try/catch around your code and then sleep forever in the catch.

But no, if you throw an unhandled exception or your process otherwise exits, Windows Azure will try to restart it. There's no way to change this behavior.


It seems a bit heavy handed, but you could try using the management API and stop the whole role in the try catch.

Personally I think it's much easier to just use Thread.Sleep(Timeout.Infinite) as smarx suggests


Smarx is right of course, but there are design patterns where you start your own web role threads and then restarting them if any unhandled exception is called. This pattern will also make you have more control over your worker roles and when to restart them and when not to. See here for one such implementation:

http://www.31a2ba2a-b718-11dc-8314-0800200c9a66.com/2010/12/running-multiple-threads-on-windows.html

0

精彩评论

暂无评论...
验证码 换一张
取 消