CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: [RESOLVED] Delegates: A simple question

Hybrid View

  1. #1
    Join Date
    Apr 2008

    [RESOLVED] Delegates: A simple question

    Hi Forum members,

    I have been refreshing my understanding of Delegates, and I have a very simple question concerning the terminology. My source of information is from the excellent book, "Pro C# 2008 and the .NET 3.5 Platform" (would highly recommend).

    While I understand the Delegate/Event model, I'm slightly confused over the terms 'caller' and 'listener'. My present understanding is that the 'caller' is the object who will assign one of it's methods to the Delegate type. And 'listener' is the aforementioned method that will be invoked when the event is fired by the Delegate; 'listener' being the 'event handler'.

    Or am I misunderstanding the terminology?

    Many thanks in advance.
    Last edited by mshdsp; January 15th, 2010 at 03:44 AM.

  2. #2
    Join Date
    Jul 2008

    Re: Delegates: A simple question

    Delegates are kind of a pointer to method.

    If you call a method from another thread, you need a delegate.

    You have your main thread of your application, but to avoid a freezed GUI,
    you have a 2nd thread, which only updates the GUI (after values have been changed).

    Your controls cannot be updated through the 2nd thread.
    It can only be controlled inside the main thread.
    Otherwise you will get an thread violation exception.

    To get access to your controls in your form (from the 2nd thread), you need
    a delegate which calls the origin method and updates the GUI.

    The delegate workaround consists of three parts:
    - the Delegate definition
    - the method to be called (e. g. updating controls)
    - invoke-call

    But I have no clue about "listener" and "caller" ;-)

  3. #3
    Join Date
    Mar 2004
    Prague, Czech Republic, EU

    Re: Delegates: A simple question

    I would say that listener is the one who subscribe to the event and caller is the one who fires it.
    • Make it run.
    • Make it right.
    • Make it fast.

    Don't hesitate to rate my post.

  4. #4
    Join Date
    Apr 2008

    Re: Delegates: A simple question

    Thanks for the responses. Much appreciated.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)