PC Review


Reply
Thread Tools Rate Thread

c# and updating the gui from a thread

 
 
fidel
Guest
Posts: n/a
 
      25th Aug 2006
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).

 
Reply With Quote
 
 
 
 
Marc Gravell
Guest
Posts: n/a
 
      25th Aug 2006
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

 
Reply With Quote
 
fidel
Guest
Posts: n/a
 
      25th Aug 2006
oh my god - that's awesome



Marc Gravell wrote:
> 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


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
updating progressbar from another thread Eps Microsoft C# .NET 0 10th Aug 2008 09:43 AM
Thread updating UI from other Classes... GTi Microsoft C# .NET 6 20th May 2005 07:07 AM
Updating the UI from a Secondary Thread BG Microsoft C# .NET 2 26th Oct 2004 05:09 AM
Updating Gui Controls from a Thread Anders Fredborg Microsoft Dot NET Compact Framework 2 12th Aug 2004 09:37 AM
updating a window from another thread Ron James Microsoft C# .NET 1 15th Aug 2003 02:44 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:22 AM.