|
-
Apr 14th, 2010, 10:05 PM
#1
Thread Starter
Addicted Member
Multithreading weirdness...
Can someone explain to me why the 1st example gives me an error complaining about cross thread yada yada....but the second doesn't, and works?
this is inside a worker thread function
Code:
form1.visible = false
Code:
if not form1.invokerequired then form1.visible = false
I understand the concept of needing delegates and all that jazz when working with multiple threads, but why give me an error if there's no invoke required anyway?
-
Apr 14th, 2010, 10:54 PM
#2
Re: Multithreading weirdness...
Is 'form1' a variable or is it a class?
-
Apr 14th, 2010, 11:01 PM
#3
Thread Starter
Addicted Member
Re: Multithreading weirdness...
Actually heres the real code....
Code:
If Me.InvokeRequired Then
Me.Invoke(New SetFormVisibleDelegate(AddressOf SetFormVisibleSub), {Me, False})
Else
Me.Visible = False
End If
but invoke is never required, yet I still get that error....
-
Apr 14th, 2010, 11:03 PM
#4
Re: Multithreading weirdness...
In that case the second code is not working. It might appear to but it's not. It's creating a new instance of Form1 on that secondary thread and displaying that, not the original instance. That's bad for various reasons. For more information, you might like to follow the Blog link in my signature and check out my post on Default Form Instances.
-
Apr 14th, 2010, 11:04 PM
#5
Thread Starter
Addicted Member
Re: Multithreading weirdness...
I'm just gonna eventually take the time to make all the changes to get it over to non-default instancing....just haven't taken the time yet...thx for the info
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
|