PC Review


Reply
Thread Tools Rate Thread

Trying to use anonymous methods to invoke code on a control

 
 
=?Utf-8?B?QnJhZA==?=
Guest
Posts: n/a
 
      2nd Mar 2007
With the full .net compact framework, if you want to update a control from a
different thread from which it was created, and you want to use an anonymous
method to invoke your delegate to do the code, you do something like this:

this.Invoke((MethodInvoker)delegate()
{
this.Text = "x";
});

But with the .net compact framework it looks like MethodInvoker is not
supported. So does anyone know how I would do the equivalent when using the
compact framework? I don't want to have to explicitly create the delegate
function. I want to use an anonymous method to do it.

Thanks,

Brad
 
Reply With Quote
 
 
 
 
Tomer Gabel
Guest
Posts: n/a
 
      4th Mar 2007
Hello Brad,

Just declare a private delegate for that purpose. You could even cast to
a completely arbitrary delegate type (EventHandler for instance) and it'll
usually work, but is not as elegant.

I usually just redeclare a "private static delegate void MethodInvoker();"
and use that.

Regards,
Tomer Gabel (http://www.tomergabel.com)
Monfort Software Engineering Ltd. (http://www.monfort.co.il)


> With the full .net compact framework, if you want to update a control
> from a different thread from which it was created, and you want to use
> an anonymous method to invoke your delegate to do the code, you do
> something like this:
>
> this.Invoke((MethodInvoker)delegate()
> {
> this.Text = "x";
> });
> But with the .net compact framework it looks like MethodInvoker is not
> supported. So does anyone know how I would do the equivalent when
> using the compact framework? I don't want to have to explicitly create
> the delegate function. I want to use an anonymous method to do it.
>
> Thanks,
>
> Brad
>



 
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
Control.Invoke and anonymous methods Lee Crabtree Microsoft Dot NET Framework Forms 1 27th Aug 2007 12:33 AM
Control access: Anonymous Methods, MethodInvoker _DD Microsoft C# .NET 4 25th May 2006 09:40 PM
using anonymous methods Alexandre Microsoft ASP .NET 7 8th Feb 2006 04:08 AM
Code behind Control.Invoke =?Utf-8?B?SlBSb290?= Microsoft Dot NET Framework Forms 3 5th Feb 2004 07:15 AM
invoke methods on the parent page from the user control Max Microsoft ASP .NET 3 24th Jan 2004 01:09 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:45 PM.