PC Review Forums Newsgroups Microsoft DotNet Microsoft Dot NET Compact Framework Trying to use anonymous methods to invoke code on a control

Reply

Trying to use anonymous methods to invoke code on a control

 
Thread Tools Rate Thread
Old 02-03-2007, 10:43 PM   #1
=?Utf-8?B?QnJhZA==?=
Guest
 
Posts: n/a
Default Trying to use anonymous methods to invoke code on a control


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
Old 04-03-2007, 03:19 PM   #2
Tomer Gabel
Guest
 
Posts: n/a
Default Re: Trying to use anonymous methods to invoke code on a control

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off