Control invoking w/o creating a delegate

S

Steve B.

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
 
R

Roman Wagner

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().
 
S

Steve B.

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top