|
-
Sep 16th, 2008, 05:42 AM
#1
Thread Starter
Lively Member
problem with thread safe changing controls-agian
now that ive changed my code around i can no longer change a control on my main form from a class thats being run on a different thread.
my onload event has this:
Code:
WC = New Class2
ThreadingPool.QueueUserWorkItem(AddressOf WC.FindMyPort)
which runs the wc.findmyport sub in the class2 class. i tried using this:
Code:
Private Delegate Function GetControlTextInvoker(ByVal ctl As Control) As String Private Function GetControlText(ByVal ctl As Control) As String
Dim text As String
If ctl.InvokeRequired Then
text = CStr(ctl.Invoke(New GetControlTextInvoker(AddressOf GetControlText), ctl))
Else
text = ctl.Text
End If
Return textEnd Function
but its not longer working. i assume because im working with two different classes. ive tried changing everything from private to public. what i want to do is change a label's text on my main form from my class2 class being run on a seperate thread
th
I am using Microsoft Visual Basic 2008 Express Edition. I use Access for my data base
-
Sep 16th, 2008, 07:26 AM
#2
Re: problem with thread safe changing controls-agian
Um, you say that you want to change the Text on a Label, which would mean setting it, yet you're using a method named GetControlText. Do you see an issue there? At no point does that GetControlText method change any property of the control you pass to it. I think you've just ripped that code from my multi-threading example without actually working your way through the steps I outlined. The first step is to write a simple method that performs the action you want performed. If you'd done that I don't see that you could have ended up with that result. This is what so often happens when people copy and paste code without properly reading the instructions that go with it, which is why I prefer to avoid posting code a lot of the time.
-
Sep 16th, 2008, 09:54 AM
#3
Thread Starter
Lively Member
Re: problem with thread safe changing controls-agian
busted. put in my deffence ive been staring at this screen for 9 hours. im a little punchie. im just having trouble understanding how it works.
I am using Microsoft Visual Basic 2008 Express Edition. I use Access for my data base
-
Sep 16th, 2008, 11:43 AM
#4
Re: problem with thread safe changing controls-agian
Code:
Private Delegate Sub SetLabelTextInvoker(ByVal txt As String)
Private Sub SetLabelText(ByVal txt As String)
If Me.Label1.InvokeRequired Then
Me.Label1.Invoke(New SetLabelTextInvoker(AddressOf SetLabelText), txt)
Else
Me.Label1.Text = txt
End If
End Sub
-
Sep 16th, 2008, 06:57 PM
#5
Re: problem with thread safe changing controls-agian
I spent a lot of time and put a lot of effort into that thread. The second post addresses EXACTLY what you're asking here. If you'd simply read the thread and followed it STEP BY STEP you would have had your solution. I'm glad to see my efforts weren't wasted.
-
Sep 17th, 2008, 05:21 AM
#6
Re: problem with thread safe changing controls-agian
ah don't get pissed jmc, some people need it spelled out once or twice before they get it..
-
Sep 17th, 2008, 08:43 AM
#7
Re: problem with thread safe changing controls-agian
 Originally Posted by MaximilianMayrhofer
ah don't get pissed jmc, some people need it spelled out once or twice before they get it..
Noone needs something spelled out twice. They just need to read what's been spelled out the first time. If your first instinct is to copy the code and ignore the information then you simply will not learn. Some pasted code may or may not fix the immediate problem but reading a provided explanation that's intended to give you an understanding will actually teach you something.
-
Sep 17th, 2008, 10:22 AM
#8
Re: problem with thread safe changing controls-agian
Teach a man to fish
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|