question about Ice.Application behavior

changchang Member shen changOrganization: nasaProject: AMO HDU ✭✭
Hi, All

I have a DLL class inherited from Ice.Application.
The propose of this class is that once it is instantiated and initialized, the object acts as a worker and I can use this object for sending data whenever I needed without re-initial it again.

I use Ice.Application's main(args, configfile) for initialization the properties of the class, (including its Communicator, and all those proxies), since main in turns calls run(args). But the problem is when the run() returns, the communicator is destroyed and so does all the proxy properties, etc. I no longer can use this object.

Is there any way that those properties can be preserved? Did I used wrong base class (Ice.Application)?

The question is for the above class design, especially it will be used by a Win Form program, which base class of Ice framework I should use?

Shall I use Util class instead of Ice.Application or I went to the wrong direction?

Thanks

Chang

Comments

  • xdmxdm La Coruña, SpainAdministrators, ZeroC Staff Jose Gutierrez de la ConchaOrganization: ZeroC, Inc.Project: Ice Developer ZeroC Staff
    Hi,

    Ice.Application is intended to be used by Console applications, for GUI applications, you just need to initialize the communicator using one of the helper methods in Ice.Util and destroy it when before exit the application

    See demo/Ice/wpf for a C# GUI application demo using Windows Presentation Foundation Framework.

    Look in HelloWindow.xaml.cs file, the basic is:
            private void Window_Loaded(object sender, EventArgs e)
            {
                try
                {
                    Ice.InitializationData initData = new Ice.InitializationData();
                    initData.properties = Ice.Util.createProperties();
                    initData.properties.load("config.client");
                    initData.dispatcher = delegate(System.Action action, Ice.Connection connection)
                    {
                        Dispatcher.BeginInvoke(DispatcherPriority.Normal, action);
                    };
                    _communicator = Ice.Util.initialize(initData);
                }
                catch(Ice.LocalException ex)
                {
                    handleException(ex);
                }
            }
    
            private void Window_Closed(object sender, EventArgs e)
            {
                if(_communicator == null)
                {
                    return;
                }
    
                _communicator.destroy();
                _communicator = null;
            }
    
  • changchang Member shen changOrganization: nasaProject: AMO HDU ✭✭
    C# Windows form

    Hi XDM, Thanks for reply
    Dispatcher is a component of WPF for background worker thread. If I use a classical Win form, do I still need this delegate:

    initData.dispatcher = delegate(System.Action action, Ice.Connection connection)
    {
    Dispatcher.BeginInvoke(DispatcherPriority.Normal, action);
    };
  • benoitbenoit Rennes, FranceAdministrators, ZeroC Staff Benoit FoucherOrganization: ZeroC, Inc.Project: Ice ZeroC Staff
    Hi,

    The purpose of this delegate is to ensure that incoming calls or AMI replies will be dispatched by the GUI thread. For simple applications which don't need multi-threading and don't have complex call flows (such as nested invocations), this can simplify the coding as there's no need to implement any synchronization between the Ice threads and the GUI thread to ensure thread-safety.

    Note that this requires however the use of AMI for Ice calls made on the GUI thread (which is always a good idea anyway to avoid blocking the UI thread while waiting for the response of a server invocation...).

    If you prefer incoming request or AMI callbacks to be dispatched on the Ice threads, you shouldn't set this dispatcher and instead you should make sure that the code executed on the Ice threads access the UI elements in a thread-safe way.

    Cheers,
    Benoit.
Sign In or Register to comment.