I am stuck at one multithreaded app. Basically I am trying to update one control from background thread.

There are two forms.
1) frmMain
2) frmLog

frmLog has one list box (lstStatus) and one function as following

Public Sub SetStatus(txt as string) as string
lstStatus.Items.add(txt)
End Sub

frmMain has background worker and it calls frmLog.Setstatus("status here"). I tried various methods but somehow that listbox is not being updated when method is called from background worker.

I had also tried .InvokeRequired and .Invoke method but .invokerequired always returned me false so nothing helped, not sure if I had missed anything in that.

Please help...

Recommended Answers

All 6 Replies

Inorder to reflect the added items try

Public Sub SetStatus(txt as string) as string
lstStatus.Items.add(txt)
lstStatus.Refresh
System.Windows.Forms.Application.Doevents() ' gives time to refresh the screen
End Sub

Hope this helps

Inorder to reflect the added items try

Public Sub SetStatus(txt as string) as string
lstStatus.Items.add(txt)
lstStatus.Refresh
System.Windows.Forms.Application.Doevents() ' gives time to refresh the screen
End Sub

Hope this helps

Still not reflecting :(

I'm confused.
Do you find all the items added to the list box in the listbox.items collection?

Just to debug, add a msgbox lstStatus.Items.Count after adding the txt to verify if the counter increases.

Please let us know the results

Item is getting added in Items collection during debug.

I am also changing selected index to last added item. So if I set msgbox in selectedindexchanged property to display current number of items, it keep increasing, so it's being added.

I added another msgbox to display number of items in Click event of that listbox, it returns always zero. It behaves like it's creating a different instance of control while operating from backgroundworker. I had noticed such behaviour while accessing some variables too. Not sure what I am doing wrong.

Backgroundworker is set to reportprogress and supportcancellation.

could you please post your code that belongs to the whole case? such as the source of listbox items, the backgroundworker initializing and its methods?

man..it was a stupid mistake. i realized that while i was copying/pasting code here to show u.

thanks a lot. it's working now.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.