meofcourse
New member
- Joined
- Jan 10, 2010
- Messages
- 4
- Programming Experience
- Beginner
First off, I am quite confused....
I have done some googling and found the following links with regards to using delegates to change values in the main thread:
Shabdar.org - Free open source projects
CodeProject: Prevent 'cross-thread operation not allowed' exception through reflection. Free source code and programming help
Cross-thread operation not valid: .NET Cross Threading To Update Form Control « DataBatrix
I think I understand where that approach is coming from. Now let me explain what I am doing:
I am writing an app that rips a cd and uploads it to a website. I would like it threaded so that my cancel button is accessible as well as my progress bars are updated. So basically this is what I have set up:
Main Form contains a drop down menu with a list of cd drives.
When the start button is clicked, a new thread is started which rips the tracks from the cd.
In order for the new thread to be able to rip the cd, it needs to know what drive to rip from. However, that information is in the main thread, and not accessible to my new thread. All the examples I found all show how to assign values to a different thread, but not how to get values from another thread.
Here is my existing code:
I have done some googling and found the following links with regards to using delegates to change values in the main thread:
Shabdar.org - Free open source projects
CodeProject: Prevent 'cross-thread operation not allowed' exception through reflection. Free source code and programming help
Cross-thread operation not valid: .NET Cross Threading To Update Form Control « DataBatrix
I think I understand where that approach is coming from. Now let me explain what I am doing:
I am writing an app that rips a cd and uploads it to a website. I would like it threaded so that my cancel button is accessible as well as my progress bars are updated. So basically this is what I have set up:
Main Form contains a drop down menu with a list of cd drives.
When the start button is clicked, a new thread is started which rips the tracks from the cd.
In order for the new thread to be able to rip the cd, it needs to know what drive to rip from. However, that information is in the main thread, and not accessible to my new thread. All the examples I found all show how to assign values to a different thread, but not how to get values from another thread.
Here is my existing code:
VB.NET:
Private Sub cmdRip_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdRip.Click
Dim t As System.Threading.Thread
t = New System.Threading.Thread(AddressOf RipCDTracks)
t.Start()
Exit Sub
VB.NET:
Private Delegate Sub SetControlValueCallback(ByVal oControl, ByVal propName, ByVal propValue)
VB.NET:
Private Sub RipCDTracks()
If Me.cboDevice.InvokeRequired Then
<<------This is where I am having issues. How do I get the value of me.cbodevice.selectedindex when I am in another thread? ------>>
Else
drivenum = Me.cboDevice.SelectedIndex
End If
.....Rest of code to actually rip the tracks
End Sub