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.
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,
Looking at the source of the System.Timers.Timer component, the property looks like:
public ISynchronizeInvoke SynchronizingObject
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);
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)
Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation, please create a new thread in our Forums, or Contact Us and let us know.