Tech Off Thread

2 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

Defining a component's default properties

Back to Forum: Tech Off
  • User profile image
    Andrew Davey

    Hello fellow 9ers,

    I am creating a component that exposes the following property to enable events to be raised on the host form, in that form's main thread.

    SynchronizingObject() As System.ComponentModel.ISynchronizeInvoke

    Everthing works fine, except I cannot work out the attribute needed to make the designer automatically set that property to "Me" (i.e. the form) when added to a form. The Timer component does this so it is possible.

    Any ideas? Thanks,


  • User profile image

    Looking at the source of the System.Timers.Timer component, the property looks like:

    public ISynchronizeInvoke SynchronizingObject
            IDesignerHost host1;
            object obj1;
            if ((this.synchronizingObject == null) && base.DesignMode)
                host1 = ((IDesignerHost) this.GetService(typeof(IDesignerHost)));
                if (host1 != null)
                    obj1 = host1.RootComponent;
                    if ((obj1 != null) && ((obj1 as ISynchronizeInvoke) != null))
                        this.synchronizingObject = ((ISynchronizeInvoke) obj1);
            return this.synchronizingObject;
            this.synchronizingObject = value;

    An alternative is to look at the target of the event handlers, to see if they support ISynchronizeInvoke:

    public static void Fire(Delegate del, bool async, params object[] args)
        if (null == del) return;
        Delegate[] list = del.GetInvocationList();
        if (null == list || 0 == list.Length) return;
        for(int i=0; i<list.Length; i++)
            Delegate d = list[i];
            ISynchronizeInvoke isi = del.Target as ISynchronizeInvoke;
            if (null == isi || !isi.InvokeRequired)
                isi.Invoke(d, args);

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.