Click here to Skip to main content
15,887,214 members
Home / Discussions / C#
   

C#

 
GeneralRe: BackGroundWorker gives runtime error Pin
OriginalGriff10-Feb-21 5:43
mveOriginalGriff10-Feb-21 5:43 
GeneralRe: BackGroundWorker gives runtime error Pin
Alex Dunlop12-Feb-21 1:44
Alex Dunlop12-Feb-21 1:44 
GeneralRe: BackGroundWorker gives runtime error Pin
OriginalGriff12-Feb-21 2:11
mveOriginalGriff12-Feb-21 2:11 
GeneralRe: BackGroundWorker gives runtime error Pin
Alex Dunlop12-Feb-21 6:03
Alex Dunlop12-Feb-21 6:03 
AnswerRe: BackGroundWorker gives runtime error Pin
Ralf Meier10-Feb-21 4:48
mveRalf Meier10-Feb-21 4:48 
GeneralRe: BackGroundWorker gives runtime error Pin
Alex Dunlop10-Feb-21 4:57
Alex Dunlop10-Feb-21 4:57 
GeneralRe: BackGroundWorker gives runtime error Pin
Alex Dunlop10-Feb-21 7:47
Alex Dunlop10-Feb-21 7:47 
GeneralRe: BackGroundWorker gives runtime error Pin
Luc Pattyn10-Feb-21 9:26
sitebuilderLuc Pattyn10-Feb-21 9:26 
Here is a very good Article: Invalid cross-thread operations[^]. In its first appendix, it presents a simple BackGroundWorker example.

However, you probably don't need to Invoke at all:
- do NOT touch Controls inside DoWork
- set your Controls the way you want them just before starting the BGW (e.g. disable a Button and/or show a ProgressBar)
- use the progress event handler to report progress, where you are allowed to touch Controls
- use the completed event to re-adjust Controls (e.g. re-enable a Button and/or hide a ProgressBar).

That's it; no Invoke at all.

And then, don't try to re-use a BackGroundWorker. If you have another background job, just create and set-up a new BackGroundWorker; they aren't expensive and they use pooled threads (from the ThreadPool).

Smile | :)
Luc Pattyn [My Articles]
If you can't find it on YouTube try TikTok...


modified 10-Feb-21 16:27pm.

GeneralRe: BackGroundWorker gives runtime error Pin
Alex Dunlop10-Feb-21 16:49
Alex Dunlop10-Feb-21 16:49 
GeneralRe: BackGroundWorker gives runtime error Pin
Luc Pattyn10-Feb-21 17:22
sitebuilderLuc Pattyn10-Feb-21 17:22 
GeneralRe: BackGroundWorker gives runtime error Pin
Alex Dunlop13-Feb-21 8:24
Alex Dunlop13-Feb-21 8:24 
GeneralRe: BackGroundWorker gives runtime error Pin
Luc Pattyn13-Feb-21 8:28
sitebuilderLuc Pattyn13-Feb-21 8:28 
AnswerRe: BackGroundWorker gives runtime error Pin
Ralf Meier10-Feb-21 20:22
mveRalf Meier10-Feb-21 20:22 
AnswerRe: BackGroundWorker gives runtime error Pin
Eddy Vluggen11-Feb-21 14:21
professionalEddy Vluggen11-Feb-21 14:21 
QuestionMonitor data using C# and ESP8266 Pin
pinout_19-Feb-21 1:56
pinout_19-Feb-21 1:56 
AnswerRe: Monitor data using C# and ESP8266 Pin
OriginalGriff9-Feb-21 2:20
mveOriginalGriff9-Feb-21 2:20 
GeneralRe: Monitor data using C# and ESP8266 Pin
pinout_19-Feb-21 2:31
pinout_19-Feb-21 2:31 
AnswerRe: Monitor data using C# and ESP8266 Pin
Gerry Schmitz9-Feb-21 7:54
mveGerry Schmitz9-Feb-21 7:54 
QuestionSerialize File from one format(AMI ) to another(BAI2) format Pin
Sasikalav8-Feb-21 19:31
Sasikalav8-Feb-21 19:31 
AnswerRe: Serialize File from one format(AMI ) to another(BAI2) format Pin
OriginalGriff8-Feb-21 20:04
mveOriginalGriff8-Feb-21 20:04 
QuestionExistence of “Add” Function causes WCF to Fail Pin
Bernhard Hiller8-Feb-21 0:44
Bernhard Hiller8-Feb-21 0:44 
AnswerRe: Existence of “Add” Function causes WCF to Fail Pin
Pete O'Hanlon8-Feb-21 1:42
mvePete O'Hanlon8-Feb-21 1:42 
GeneralRe: Existence of “Add” Function causes WCF to Fail Pin
Bernhard Hiller8-Feb-21 2:10
Bernhard Hiller8-Feb-21 2:10 
GeneralRe: Existence of “Add” Function causes WCF to Fail Pin
Pete O'Hanlon8-Feb-21 2:12
mvePete O'Hanlon8-Feb-21 2:12 
GeneralRe: Existence of “Add” Function causes WCF to Fail Pin
OriginalGriff8-Feb-21 4:01
mveOriginalGriff8-Feb-21 4:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.