Results 1 to 5 of 5

Thread: Multithreading weirdness...

  1. #1

    Thread Starter
    Addicted Member theonetrueace's Avatar
    Join Date
    Jan 2002
    Location
    South Alabama
    Posts
    196

    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?

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Multithreading weirdness...

    Is 'form1' a variable or is it a class?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Addicted Member theonetrueace's Avatar
    Join Date
    Jan 2002
    Location
    South Alabama
    Posts
    196

    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....

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Addicted Member theonetrueace's Avatar
    Join Date
    Jan 2002
    Location
    South Alabama
    Posts
    196

    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
  •  



Click Here to Expand Forum to Full Width