I have two questions about using a BackgroundWorker:
1)Lets say you have Function A and Function B. Function A creates a BackgroundWorker which runs Function B. So the BackgroundWorker is now running Function B on a separate thread. Function B is an infinite while loop that I intend to run for a long duration. After Function A uses the BackgroundWorker through, it returns. So now that the function that initiated the BackgroundWorker (Function A) has returned, does the BackgroundWorker thread keep running in the background? Or does it stop running Function B since the function that instantiated it has returned? If it does stop, how would I make it so that Function B continues to run even after Function A has returned?
2)I need to access Window Forms Items (i.e. Textbox) from a separate thread created by a BackgroundWorker. However if I try to access Window Forms Items from a thread that is not main, I get a cross threading error. How could I safely access Window Forms Items from a separate thread? I basically need to keep updating a textbox from a separate thread. I know a BackgroundWorker has a member called "RunWorkerCompleted" and that is run after the BackgroundWorker completes its job. It allows me to access Window Forms Items from this. However, I need to access a Window Forms Item during the duration of my thread rather than after its completion. How could I access these safely through a thread? If this isn't possible what are some other possible solutions to the problem?