c# and updating the gui from a thread

  • Thread starter Thread starter fidel
  • Start date Start date
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).
 
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
 
Back
Top