Click here to Skip to main content
15,662,659 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I keep receiving an error of:

Error 2 An object reference is required for the non-static field, method, or property 'System.ComponentModel.BackgroundWorker.ReportProgress(int)'


Error 1 An object reference is required for the non-static field, method, or property 'System.ComponentModel.BackgroundWorker.RunWorkerAsync(object)

But all I did was copy and paste from another project? The other project it works just fin, why is it causing problems in a new project?

Is was for a background worker progress example: Displaying progress updates when hashing large files
Sergey Alexandrovich Kryukov 21-May-15 16:52pm    
Why so many our inquirers think that programming (or learning programming) is done by copy and paste? Did you try to actually write code understanding all you are doing (and not doing what you don't understand)? Perhaps than you would not have such problems.

1 solution

In the project you downloaded open the Form in the Forms-Designer: The author dropped a BackgroundWorker from the Toolbox (from the Components-section) onto the form and named it "BackgroundWorker" (the exact name of the class).

If you have not done the same or named your BackgroundWorker-variable differently then the compiler interpretes the identifier "BackgroundWorker" as the class name and not as a variable of the type BackgroundWorker.

So: Either have a variable named "BackgroundWorker" or replace the identifier "BackgroundWorker" by the name of your existing variable.
Share this answer
Herboren 21-May-15 15:30pm    
Wow thank you soo much, I can't believe I didn't see this. I never knew there was a control for this. This cleared it right up, thank you so very much!
Sascha Lefèvre 21-May-15 15:42pm    
You're welcome! :)
Sergey Alexandrovich Kryukov 21-May-15 16:55pm    
5ed, but... The root of the problem is the way the inquirer tries to learn things. But it's good that he probably understood your answer; I did not expect that.
Please see my comment to the question.
Still, I'm not sure the essence of things (in this case, static vs instance members and using those instance members) is really clear to him.
Sascha Lefèvre 21-May-15 17:08pm    
Thank you, Sergey.
The OP is welcome to ask a follow-up question if there's any confusion left :)
(As I have found out from the question I posted recently, the OP receives any comments to an answer.)
Herboren 21-May-15 16:57pm    
Solutions was already given. Should just leave it at that. =\

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900