Results 1 to 2 of 2

Thread: [RESOLVED] [2008] Calling a function from another thread

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Dec 2001
    Posts
    1,331

    Resolved [RESOLVED] [2008] Calling a function from another thread

    Hello,

    I have a function which is a callback. Code sippet below.

    However, as the OnIncomingCall() will be on a different thread, I don't think it can call the IncomingCallAlert(). With controls you can use a delegate and invoke the control.

    Which is the best way to do the same with a function?

    Many thanks for any advice,

    Steve

    Code:
    private sub OnIncomingCall()
    .
    .
    IncomingCallAlert()
    .
    Sub End
    
    
    private sub IncomingCallAlert()
    'Play sound
    Sub End
    Last edited by steve_rm; May 28th, 2008 at 12:14 AM.
    steve

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

    Re: [2008] Calling a function from another thread

    You don't invoke a control. You use a control to invoke a delegate and you use the delegate to marshal a method call to the UI thread. The reason you need to do that is that you cannot access the handle of a control on a thread that doesn't own it. That's the only reason you need to do it. If you're not accessing controls then there's no need for you to do that. You can call any method you like on any thread you like. All members are available to all threads at all times. That's exactly why you need to synchronise multiple threads: because they can all access the same data.

    In short, just call the method without regard for the thread it's executing on.
    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

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