i developing mono service application on linux. want attach mono debugger running service. how can find service process? how can attach debugger it?
greetings
there excellent article mikael chudinov explaining here: http://blog.chudinov.net/demonisation-of-a-net-mono-application-on-linux/
starting base, i've made generic base class let dynamically check if debugger attached , either let debug code or start mono service normal when not being debugged.
the base class is:
using system; using nlog; using system.serviceprocess; public class ddxservice : servicebase { protected static logger logger = logmanager.getcurrentclasslogger(); protected static void start<t>(string[] args) t : ddxservice, new() { if (system.diagnostics.debugger.isattached) { logger.debug("running in debug mode"); (new t()).onstart(new string[1]); servicebase.run(new t()); } else { logger.debug("running in release mode"); servicebase[] servicestorun; servicestorun = new servicebase[] { new t() }; servicebase.run(servicestorun); } //if-else } }
for using base class, inherit , override system.serviceprocess.servicebase methods onstart , onstop. place here main method launch init sequence:
class service : ddxservice { protected override void onstart(string[] args) { //execute startup code //you can place breakpoints , debug } protected override void onstop() { //execute stop code } public static void main(string[] args) { ddxservice.start<service>(args); } }
hope helps.
Comments
Post a Comment