Hello everyone I have the following situation with the background worker and hope someone can help me with this.

1.- i have a form and in that form I have the background worker. the methods doWork, Progresschanged, Runworklercompleted are in the form.

2.- when i star doWork, it executes a method called Process1 from class AMOUNTS from another class and it works fine, the program does it's work.

3.- the thing is that i have to fill a listbox with each step the program is doing.

4.- in the main form I have a method which is public called LogEvent. in this method is where i update the listbox with the steps of the program.

5.-in Process1, i want to send those steps to the LogEvent which is on form1. but nothing is being shown.

6.- I would apreciate a code as an example, i tried to use InvokeRequired but I dont know how to make it work with methods.

Thanks in advance.

Recommended Answers

All 2 Replies

How to use a invokeRequired method while you have to invoke a control over threads shows the exmple code with using Delegates bellow:

Private Delegate Sub MyDelegate(msg As String)
Private Sub FillingListBox(value As String)
	If listBox1.InvokeRequired Then
		listBox1.Invoke(New MyDelegate(AddressOf FillingListBox), New Object() {value})
	Else
		listBox1.Items.Add(value)
	End If
End Sub

You call this method when you want to pass the new item to listBox.

Thanks for your response, however what I'm trying to do here is to call a method in the main form from a class that is being executed in the background worker.

I tried to adapt the example you gave me but for some reason its giving errors.

Thanks in advance.

How to use a invokeRequired method while you have to invoke a control over threads shows the exmple code with using Delegates bellow:

Private Delegate Sub MyDelegate(msg As String)
Private Sub FillingListBox(value As String)
	If listBox1.InvokeRequired Then
		listBox1.Invoke(New MyDelegate(AddressOf FillingListBox), New Object() {value})
	Else
		listBox1.Items.Add(value)
	End If
End Sub

You call this method when you want to pass the new item to listBox.

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.