-
January 16th, 2010, 10:23 AM
#1
BackgroundWorker with anonymous methods ?
Hi,
I'm gonna create a BackgroundWorker with an anonymous method.
I've written the following code :
PHP Code:
BackgroundWorker bgw = new BackgroundWorker(); bgw.DoWork += new DoWorkEventHandler( () => { int i = 0; foreach (var item in query2) { .... .... } } );
But Delegate 'System.ComponentModel.DoWorkEventHandler' does not take '0' arguments and I have to pass two objects to the anonymous method : object sender, DoWorkEventArgs e
Could you please guide me, how I can do it ?
Thanks.
-
January 16th, 2010, 12:38 PM
#2
Re: BackgroundWorker with anonymous methods ?
you should do exacly what the compiler is asking you to do:
PHP Code:
BackgroundWorker bw = new BackgroundWorker();
bw.DoWork += delegate(Object sender, DoWorkEventArgs e)
{
MessageBox.Show("Hi M-Dayyan!");
};
bw.RunWorkerAsync();
there are hundrets of tutorials on anonymus methods and delegates. just google
Last edited by memeloo; January 16th, 2010 at 01:49 PM.
win7 x86, VS 2008 & 2010, C++/CLI, C#, .NET 3.5 & 4.0, VB.NET, VBA... WPF is comming
remeber to give feedback you think my response deserves recognition? perhaps you may want to click the Rate this post link/button and add to my reputation
private lessons are not an option so please don't ask for help in private, I won't replay
if you use Opera and you'd like to have the tab-button functionality for the texteditor take a look at my Opera Tab-UserScirpt; and if you know how to stop firefox from jumping to the next control when you hit tab let me know
-
January 16th, 2010, 01:05 PM
#3
Re: BackgroundWorker with anonymous methods ?
Thanks my friend,
we could do that like this
PHP Code:
bgw.DoWork += new DoWorkEventHandler(
(s, e1) =>
{
int i = 0;
foreach (var item in query2)
{
....
....
}
}
);
-
January 16th, 2010, 01:09 PM
#4
Re: BackgroundWorker with anonymous methods ?
of course this time I chose the lighter method
but even this is possible:
PHP Code:
BackgroundWorker bw = new BackgroundWorker();
bw.DoWork += (sender, e) =>
{
MessageBox.Show("Hi!");
};
bw.RunWorkerAsync();
Last edited by memeloo; January 16th, 2010 at 01:47 PM.
win7 x86, VS 2008 & 2010, C++/CLI, C#, .NET 3.5 & 4.0, VB.NET, VBA... WPF is comming
remeber to give feedback you think my response deserves recognition? perhaps you may want to click the Rate this post link/button and add to my reputation
private lessons are not an option so please don't ask for help in private, I won't replay
if you use Opera and you'd like to have the tab-button functionality for the texteditor take a look at my Opera Tab-UserScirpt; and if you know how to stop firefox from jumping to the next control when you hit tab let me know
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|