Solved

delegate

Posted on 2009-04-11
2
263 Views
Last Modified: 2012-05-06
When it is right to use Delegate in Vb.net? I am a bit confused.
0
Comment
Question by:VBdotnet2005
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 5

Expert Comment

by:brandonvmoore
ID: 24124470
Delegates are generally used when there is communication going on between your code and some other external application or code/library.  A delegate is the same thing as a callback function.

Delegates are one of those things that are sometimes difficult to understand until you are actually doing something that requires one.  If you have a specific problem that you think might require one, why don't you explain it and I'll see if I can demystify it for you.
0
 
LVL 5

Accepted Solution

by:
brandonvmoore earned 125 total points
ID: 24124478
By the way, you use delegates all the time without knowing it.  All the events that you write code for (ie. a mouse click) are delegates.  But VB just takes care of the details of setting them up for you as delegates to the operating system.  Another way of thinking of delegates are as pointers to functions.

In other words, I don't actually give the operating system the actual code that I want it to run when a mouse gets clicked.  I just tell the operating where that code is by giving it a pointer (or delegate).  You really won't need to be giving any delegates to the operating system as these are built in to the language already.  But let's say that you have an application that has to get data from another application to display.  A excellent real life example of this would be a webpage.  Because the javascript on a webpage has to make a call to an asp page (written in vb) on a server to let it know what data it needs.  The webpage has no control over how long it's going to take for the server to respond and needs to keep functioning in the meantime.  So it makes a callback function to be called when the response from the server comes back.

Hope that helps.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

632 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question