borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (How to debug when developing web custom control ?)Next Topic (how to work with pointer in vb.net) New Topic New Poll Post Reply
AndreaVB Forum : ASP.Net : what is callback function
Poster Message
tri_inn
Level: Regular User
Registered: 26-08-2002
Posts: 395

icon what is callback function

please tell me in detail what is callback function with sample code.

14-06-2004 at 12:46 PM
View Profile Send Email to User Show All Posts | Quote Reply
fabulous
Level: VB Guru


Registered: 03-08-2002
Posts: 439
icon Re: what is callback function

In .NET, a callback function is much like an event or a delegate. It serves a similar purpose in that it is called when a particular process has been performed and you have to write the code for it. Basically, you create an object and send it to do something, usually in another thread or process. When the object has done what you have sent it to, it will need a way to notify you. It then calls the callback you would have used to create it. I believe that the callback is run on the same thread the worker object is in.

The signature of the callback varies depending on the object you are using. For instance, the System.Threading.Timer uses the call back mechanism to notify you at each elapsed interval. The requirement is that your callback be a Sub (void in C#) and have a single parameter of type Object which is passed ByVal. Here is an example of the code.

'the callback
Private Sub MyCallBack(ByVal state As Object)
  'whatever you want to do when the callback is called
End Sub


This is how you set up the timer to use the callback

Dim _tmr As System.Threading.Timer
_tmr = New System.Threading.Timer(New TimerCallback(AddressOf MyCallBack), Nothing, TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(1))


The above code creates an instance of the timer class that will call the callback after 5 seconds and then at 1 second intervals afterwards.

The first parameter is the address of the callback
The second parameter can be anything you want to use in the call back. This is what will be put in the callback as the state parameter.
The 3rd parameter determines how long the timer will wait before raising the first event
The 4th parameter determines the interval between subsequent  calls to the callback procedure.

Hope this helps. Happy coding.

____________________________
My boss is a Jewish Carpenter (Jesus Christ)


Brain Bench Certified VB.NET Developer

03-08-2004 at 12:53 PM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
zimcoder
Level: VB Lord


Registered: 27-10-2003
Posts: 225
icon Re: what is callback function

Thank you  Fabulous.. that was indeed a fabulous response, can you supply a working example or even an article. it will be most appreciated



____________________________
BrainBench ADO.NET and ASP.NET Certified Developer

03-08-2004 at 01:20 PM
View Profile Send Email to User Show All Posts | Quote Reply
fabulous
Level: VB Guru


Registered: 03-08-2002
Posts: 439
icon Re: what is callback function

Sure Zimcoder, I will work on an article about it and upload it soon. Happy coding.

____________________________
My boss is a Jewish Carpenter (Jesus Christ)


Brain Bench Certified VB.NET Developer

03-08-2004 at 01:34 PM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
AndreaVB Forum : ASP.Net : what is callback function
Previous Topic (How to debug when developing web custom control ?)Next Topic (how to work with pointer in vb.net) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder