protected virtual int doMain(string[] args, InitializationData initData) { int status = 0; try { // // If the process logger is the default logger, we replace it with a // a logger which is using the program name for the prefix. // if(initData.properties.getProperty("Ice.ProgramName").Length > 0 && Util.getProcessLogger() is ConsoleLoggerI) { Util.setProcessLogger(new ConsoleLoggerI(initData.properties.getProperty("Ice.ProgramName"))); } communicator__ = Util.initialize(ref args, initData); destroyed__ = false; // // The default is to destroy when a signal is received. // if(signalPolicy__ == SignalPolicy.HandleSignals) { destroyOnInterrupt(); } status = run(args); } catch(Ice.Exception ex) { Util.getProcessLogger().error(ex.ToString()); status = 1; } catch(System.Exception ex) { Util.getProcessLogger().error("unknown exception:\n" + ex); status = 1; } // // Don't want any new interrupt. And at this point // (post-run), it would not make sense to release a held // signal to run shutdown or destroy. // if(signalPolicy__ == SignalPolicy.HandleSignals) { ignoreInterrupt(); } lock(mutex__) { while(callbackInProgress__) { System.Threading.Monitor.Wait(mutex__); } if(destroyed__) { communicator__ = null; } else { destroyed__ = true; // // communicator__ != null means that it will be destroyed // next; destroyed__ == true ensures that any // remaining callback won't do anything // } _application = null; } if(communicator__ != null) { try { communicator__.destroy(); } catch(Ice.Exception ex) { Util.getProcessLogger().error(ex.ToString()); status = 1; } catch(System.Exception ex) { Util.getProcessLogger().error("unknown exception:\n" + ex); status = 1; } communicator__ = null; } return status; }
/// <summary> /// The application must call main after it has /// instantiated the derived class. main creates /// a communicator, establishes the specified signal policy, and, /// once run returns, destroys the communicator. /// The method prints an error message for any exception that propagates /// out of run and ensures that the communicator is /// destroyed correctly even if run completes abnormally. /// </summary> /// <param name="args">The arguments for the application (as passed to Main(string[]) /// by the operating system.</param> /// <param name="initializationData">Additional data used to initialize the communicator.</param> /// <returns>The value returned by run. If run terminates with an exception, /// the return value is non-zero.</returns> public int main(string[] args, InitializationData initializationData) { if(Util.getProcessLogger() is ConsoleLoggerI) { Util.setProcessLogger(new ConsoleLoggerI(appName__)); } if(communicator__ != null) { Util.getProcessLogger().error("only one instance of the Application class can be used"); return 1; } // // We parse the properties here to extract Ice.ProgramName. // InitializationData initData; if(initializationData != null) { initData = (InitializationData)initializationData.Clone(); } else { initData = new InitializationData(); } try { initData.properties = Util.createProperties(ref args, initData.properties); } catch(Ice.Exception ex) { Util.getProcessLogger().error(ex.ToString()); return 1; } catch(System.Exception ex) { Util.getProcessLogger().error("unknown exception:\n" + ex); return 1; } appName__ = initData.properties.getPropertyWithDefault("Ice.ProgramName", appName__); nohup__ = initData.properties.getPropertyAsInt("Ice.Nohup") > 0; _application = this; int status; if(signalPolicy__ == SignalPolicy.HandleSignals) { if(IceInternal.AssemblyUtil.platform_ == IceInternal.AssemblyUtil.Platform.Windows) { _signals = new WindowsSignals(); } else { _signals = new MonoSignals(); } _signals.register(_handler); status = doMain(args, initData); _signals.destroy(); _signals = null; } else { status = doMain(args, initData); } return status; }