예제 #1
0
        public override int run(string[] args)
        {
            if(args.Length > 0)
            {
                System.Console.Error.WriteLine(appName() + ": too many arguments");
                return 1;
            }

            Ice.ObjectAdapter adapter = communicator().createObjectAdapter("Callback.Server");
            CallbackSenderI sender = new CallbackSenderI(communicator());
            adapter.add(sender, communicator().stringToIdentity("sender"));
            adapter.activate();

            Thread t = new Thread(new ThreadStart(sender.Run));
            t.Start();

            try
            {
                communicator().waitForShutdown();
            }
            finally
            {
                sender.destroy();
                t.Join();
            }

            return 0;
        }
예제 #2
0
    public static int Main(string[] args)
    {
        int status = 0;

        try
        {
            //
            // using statement - communicator is automatically destroyed
            // at the end of this statement
            //
            using (var communicator = Ice.Util.initialize(ref args, "config.server"))
            {
                if (args.Length > 0)
                {
                    Console.Error.WriteLine("too many arguments");
                    status = 1;
                }
                else
                {
                    //
                    // Shutdown the communicator on Ctrl+C or Ctrl+Break
                    // (shutdown always with Cancel = true)
                    //
                    Console.CancelKeyPress += (eventSender, eventArgs) =>
                    {
                        eventArgs.Cancel = true;
                        communicator.shutdown();
                    };

                    var adapter = communicator.createObjectAdapter("Callback.Server");
                    var sender  = new CallbackSenderI(communicator);
                    adapter.add(sender, Ice.Util.stringToIdentity("sender"));
                    adapter.activate();

                    var t = new Thread(new ThreadStart(sender.Run));
                    t.Start();

                    try
                    {
                        communicator.waitForShutdown();
                    }
                    finally
                    {
                        sender.destroy();
                        t.Join();
                    }
                }
            }
        }
        catch (Exception ex)
        {
            Console.Error.WriteLine(ex);
            status = 1;
        }

        return(status);
    }