How to add text on a form, from a Background Worker?

MrLucky

Freshman
Joined
Mar 5, 2006
Messages
47
Hi,

I have a form, with a multiline textbox, and I have a background worker, which handles a connection to an IRC server.

But how can I add text to my textbox from my background worker?

Thanks in advance :)
 
Well I'll admit that I'd never heard of a BackgroundWorker, however after looking up the class I'm not convinced you need to use one. That being said the MSDN library states....

"You must be careful not to manipulate any user-interface objects in your DoWork event handler. Instead, communicate to the user interface through the ProgressChanged and RunWorkerCompleted events."

This would seem to indicate you need to use the ProgressChanged event.

http://msdn2.microsoft.com/en-US/library/system.componentmodel.backgroundworker.aspx
 
Are you using the .Net 2.0 Background Worker Control?

Basically, the way that control works is you impliment three event handlers for three basic events the background worker raises, DoWork, ProgressChanged, and RunWorkerCompleted and communicate with the controls in the main thread from those event handlers.

There are other methods you can use involving delegates, but if you are able to handle the updates in the ProgressChanged event handler, then you won't need to use them.

Edit:
And cags beat me to the punch! :) I have used the background worker and it made a lot of really complicated stuff that I was doing in 1.1 very easy when I ported the code to 2.0. It won't work in all situations, but when you can use it, it makes everything a lot easier.
 
Last edited:
Back
Top