I'm building a small application with Windows Forms and see this pattern constantly -

        public void Transfer(IList<Hash> items)
        {
            if (InvokeRequired)
            {
                Invoke(new ProcessDelegate<IList<Hash>>(Transfer), new object[] { items });
            }
            else
            {
                foreach (var e in items)
                {
                    hashBindingSource.Add(e);
                    Application.DoEvents();
                }
            }
        }

Is there a better way to do this? I imagine having an attribute on the method doing code-injection to create this pattern automatically - including creating any necessary delegate types.

Oh thread-safe scenegraph - where art thou.