c# and updating the gui from a thread

F

fidel

Hello,

I'm aware of the ways MS has recommended updating the gui from a
thread.

eg.
BeginInvoke(StartedExaminingFile, new object[] { file });

But, I really don't like this solution. The fact that you're passing an
array of objects means if the function signature changes, the invoke
would fail terribly.

With all the code-generation that goes on with .net (ie. datasets etc),
couldn't MS make a wrapper for this call? It just seems
uncharacteristic of .net to not strongly type the parameters,
considering the introduction of things like generics (and other
mechanisms for strongly typing).
 
M

Marc Gravell

in 2.0 (which you seem tobe using since you don't have "new
SomeDelegateType(StartedExaminingFile)" you can both strongly type it,
and remove the need for the function to match *any* delegate:

BeginInvoke((MethodInvoker) delegate {StartedExaminingFile(file);});

(or something similar; don't have an IDE to hand...)

The only thing to watch out for is deferred variable evaluation...

Marc
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top