Get ip adresses on a lan with backgroundworker control?

As Chris and Reed stated....you can only modify a Ui control from the thread that the control was created on.

As Chris and Reed stated....you can only modify a Ui control from the thread that the control was created on... You can also use the BackgroundWorker's ProgressChanged event for Ui updates.... var worker = new BackgroundWorker() { WorkerReportsProgress = true, WorkerSupportsCancellation = true }; /// runs on background thread worker. DoWork += (s, e) => { while (!done) { DoSomeWork(); // send a message to the Ui // via the ProgressChanged event worker. ReportProgress(percent, statusMessage); } }; /// the ProgressChanged event runs on the UI thread worker.

ProgressChanged += (s, e) => { var msg = (MyStatusMessage)e. UserState; someUiControl.Items. Add(msg.

Text); }; /// also runs on Ui thread worker. RunWorkerCompleted += (s, e) => { }; worker.RunWorkerAsync().

Thanks for your answer. I understand to get my records in worker. ProgressChanged event.

I will try this but I want to use multi thread because there are mode than 1000 computers in my network. Can I do something with backgroundworker? – Rapunzo Jul 21 '10 at 8:08.

You cannot and should not access UI controls from any thread other than the thread that created the control. I guess your deadHostList is a ListView control or something similar. You can marshal a request from the background thread to the UI thread by using Control.

Invoke or Control.BeginInvoke.

You need to always marshal calls to UI elements, such as your list control, onto the UI thread. You can do this via Control.Invoke. Change this: deadHostList.Items.

Add(machine. Name); To: string name = machine. Name; deadHostList.

Invoke(new Action( () => deadHostList.Items. Add(name))); You'll also need to do the same thing later for ListHostIP - make sure to use Control. Invoke to wrap that call as well.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions