sirbounty
asked on
Cross-thread operation not valid: Control 'frmMain' accessed from a thread other than the thread it was created on.
How can I correct this?
Using vb.net 2k5
In my sub, I have
Dim t As New Thread(AddressOf ShowHistory)
t.Start()
In ShowHistory sub, it bombs on the .view=view.details line below
With lsvHistory
.Clear()
.View = View.Details
.Columns.Add("Date", 70, HorizontalAlignment.Left)
'[....]
Using vb.net 2k5
In my sub, I have
Dim t As New Thread(AddressOf ShowHistory)
t.Start()
In ShowHistory sub, it bombs on the .view=view.details line below
With lsvHistory
.Clear()
.View = View.Details
.Columns.Add("Date", 70, HorizontalAlignment.Left)
'[....]
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hmm - thought it was going to work, but then it bombed with the same error on the next line...So 'all' changes to this control will need to be moved to the OutputMessage sub?
ASKER
Yeah, I already found the msdn article...didn't want to cheat this time around... :^)
I'll have at least two...probably more.
I'm trying to have these subs take off on their own...right now my form is locked when these calls are made. I want the user to be able to fill in a couple of text boxes while they wait...
I'd like to implement this on a couple of functions in my modules too - but will ask a seperate question on that once this is sorted.
I'll have at least two...probably more.
I'm trying to have these subs take off on their own...right now my form is locked when these calls are made. I want the user to be able to fill in a couple of text boxes while they wait...
I'd like to implement this on a couple of functions in my modules too - but will ask a seperate question on that once this is sorted.
ASKER
I 'think' it's working...did I do it right?
Sub ShowHistory()
'I've removed 'everything' from here and moved it to OutputMessage (under your test for Invokerequired)
OutputMessage("Hello") 'But I'm confused on the string...what's the point? : \
End Sub
So, should I have moved 'all' processing into that delegate?
Sub ShowHistory()
'I've removed 'everything' from here and moved it to OutputMessage (under your test for Invokerequired)
OutputMessage("Hello") 'But I'm confused on the string...what's the point? : \
End Sub
So, should I have moved 'all' processing into that delegate?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I think with that last confirmation, I'm all set...I removed the string requirements - would like to know if they're needed (probably for just passing simple text to a textbox?)
As a followup - if I was creating 'another' thread - I'd need another delegate sub and related sub to process that, correct?
As a followup - if I was creating 'another' thread - I'd need another delegate sub and related sub to process that, correct?
ASKER
Okay, great...so going off what you've posted...could that same methodology be used for different threads?
Something like:
Dim t As New Thread(AddressOf StartThread)
t.Start()
Sub StartThread (caller?)
If caller=History Then
ShowHIstory()
Else
ShowSomethingElse
End If
End Sub
Or would I need something specific for each thread?
Something like:
Dim t As New Thread(AddressOf StartThread)
t.Start()
Sub StartThread (caller?)
If caller=History Then
ShowHIstory()
Else
ShowSomethingElse
End If
End Sub
Or would I need something specific for each thread?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
not sure what you mean by the last question. If I am catching you right, Yes that would work fine. You can call ShowHistory from any thread.
ASKER
I'm not sure what I'm saying either...doing it will prove it to me.
Thanx much for the info!
Thanx much for the info!
ASKER
Sweet - it works! :^)
ASKER
If you're interesting in helping me again, along the same lines...
https://www.experts-exchange.com/questions/22477954/vb-net-2005-threading-Parameter-count-mismatch.html
https://www.experts-exchange.com/questions/22477954/vb-net-2005-threading-Parameter-count-mismatch.html
ASKER
Still need some help here.
So, if I were, in this example, trying to simply change the listbox's view property to 'viewdetails', I would add the delegate, then the OutputMessage Sub, then....? What?
Presumably I need to remove the .view=view.details from the ShowHistory sub - but what to I place there? I'm not setting any string, so I'm 'guessing' the delegate would need to be altered?