Hi,

I'm building a smart device windows app that performs some background
operation and that requires updating a progress bar.
Since I need to use the progress bar thread, I call MyProgressBar.Invoke()
method where I pass a delegate object.

The syntax is quite painfull since I need to create a custom delegate for
each modification of any control.

I'd like to use the anonymous delegate pattern, but it does not compile :

stepProgressBar.Invoke(
delegate(int progress)
{
_stepProgressBar.Value = progress;
},
new object[] { e.Progress }
);

The error is this error :
The best overloaded method match for
'System.Windows.Forms.Control.Invoke(System.Delegate, params object[])' has
some invalid arguments
Error 10 Argument '1': cannot convert from 'anonymous method' to
'System.Delegate'

I'd like to avoid building a custom delegate type like
public delegate void UpdateProgressBarDelegate(ProgressBar bar, int
progress);

Is there any correct syntax to reach my goal ?
Thanks,
Steve

Re: Control invoking w/o creating a delegate by Roman

Roman
Tue Oct 24 04:07:24 CDT 2006

Don't know whether you can fix this delegate problem. But why don't you
use BackgroundWorker? With backgroundworker there is no need to use
Invoke().


Re: Control invoking w/o creating a delegate by Steve

Steve
Tue Oct 24 04:17:59 CDT 2006

I don't use background worker since it does not exist in smartdevice
applications :)

But even if the bg worker have existed, the bg worker is sometimes quite
"too much" and moreover, I really like to know if there is an answer to my
question since threading in windows app is a recurent "problem" the BG
worker cannot always solve...

Thanks,
Steve

"Roman Wagner" <roman.wagner@gmail.com> a écrit dans le message de news:
1161680844.549191.207020@m73g2000cwd.googlegroups.com...
> Don't know whether you can fix this delegate problem. But why don't you
> use BackgroundWorker? With backgroundworker there is no need to use
> Invoke().
>