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.
-
-
To preempt any answers, I looked at google and found this
-
After only finding AOP approaches to this on the google, I suggested an extension method solution recently on C9. What do you think of that approach?
-
You searched the Internet using Google, found and looked at "ISerializable - Roy Osherove's Blog"... *correcting*esoteric said:
Edit : What I mean is, Google != Internet
ps. Yes, I know... Off topic!
-
I don't like the current way either and therefore implemented a small class to help me out: http://www.liensberger.it/web/blog/?p=90 - I hope that helps you guys too.
The approach could be modified to use extension methods, but I didn't do that to keep it compilable for the C# 2.0 compiler. -
Hmm... why would you bother to do that when Invoke/InvokeRequired are bugged in all kinds of ways? What's wrong with using BackgroundWorker or SynchronizationContext?littleguru said:I don't like the current way either and therefore implemented a small class to help me out: http://www.liensberger.it/web/blog/?p=90 - I hope that helps you guys too.
The approach could be modified to use extension methods, but I didn't do that to keep it compilable for the C# 2.0 compiler. -
Not bad, but still not quite as transparent as one would like.dcuccia said:After only finding AOP approaches to this on the google, I suggested an extension method solution recently on C9. What do you think of that approach?
Thread Closed
This thread is kinda stale and has been closed but if you'd like to continue the conversation, please create a new thread in our Forums,
or Contact Us and let us know.