473,320 Members | 1,879 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Please explain the term Callback

(1.) What is the general meaning of the term 'callback'?
(2.) What does 'callback' mean, as used in the context of threading?

Many thanks,
Zach.
Nov 16 '05 #1
4 1753
I can help you with #1. Unfortunately I don't know much about threading
yet, so someone else will have to help you with #2.

A "callback" (which in C# is implemented using a delegate) is a pointer
or some other handle to a method that you pass to another object so
that the target object can "call you back" for some reason.

For example, take a look at the Image.GetThumbnailImage method. I call
this method to scale some images that I'm displaying in a picture
gallery. However, scaling an image is a CPU-intensive operation that
can take a while. For a large, complicated image, it can go away for a
few seconds (on my machine) before it comes back with the scaled image.
So what if my user gets tired of waiting and just wants to abandon the
effort? Well, I would want to throw up one of those progress bar
dialogs with a "Cancel" button on it, so that my user can say, "Enough
already. Forget it!" and I would stop producing the thumbnail.

However, I'm stuck. I can't do that because I called the
GetThumbnailImage method, so my object no longer has control of the
CPU... it's sitting on the stack somewhere waiting for
GetThumbnailImage to return so that it can continue executing my code.
No matter what I do, I can't make my code execute because my thread of
execution is busy in some code deep inside the Image class.

So, GetThumbnailImage gives me the option to supply a "pointer" to a
function _in my code_ that it promises to call from time to time. If
_my_ callback function, which I wrote and passed to GetThumbnailImage,
ever returns false, GetThumbnailImage will stop scaling the image and
return to its caller... my method. So, now I have the power to ask
GetThumbnailImage to stop working. I can write a little method that
every time it's called checks to see if the user has pressed the Cancel
button and, if the user has pressed the button, returns false.

Without that callback method, once I called GetThumbnailImage I would
be stuck waiting for it until it returned with the scaled image, no
matter what.

Nov 16 '05 #2
"Bruce Wood" <br*******@canada.com> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...
<snipped>

That is a very nice explanation,
thank you!
Zach.
Nov 16 '05 #3

"Zach" <00@00.00> wrote in message
news:c6***************************@freeler.nl...
(2.) What does 'callback' mean, as used in the context of threading?


To answer your second question, since Bruce did so well on your first,
callbacks within the context of threading are the same thing as they are in
all other cirucmstances, that is a method that is called back at some point
to provide information.
When you provide a callback in a threaded app, usually that callback is used
to notify an object or another thread(if the callback is marshaled back to
the original thread) that some processing has been completed.

..NETs async IO model uses callbacks quite frequently, for example, you can
issue an async read(which operates on a seperate thread or thread pool,
depending on the implementation) and have it call your method back when the
read has completed.
Nov 16 '05 #4

"Daniel O'Connell [C# MVP]" <onyxkirx@--NOSPAM--comcast.net> wrote in
message news:#4**************@TK2MSFTNGP10.phx.gbl...

"Zach" <00@00.00> wrote in message
news:c6***************************@freeler.nl...
(2.) What does 'callback' mean, as used in the context of threading?

To answer your second question, since Bruce did so well on your first,
callbacks within the context of threading are the same thing as they are

in all other cirucmstances, that is a method that is called back at some point to provide information.
When you provide a callback in a threaded app, usually that callback is used to notify an object or another thread(if the callback is marshaled back to
the original thread) that some processing has been completed.

.NETs async IO model uses callbacks quite frequently, for example, you can
issue an async read(which operates on a seperate thread or thread pool,
depending on the implementation) and have it call your method back when the read has completed.

Thank you!
Zach.
Nov 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

31
by: Raymond Hettinger | last post by:
Based on your extensive feedback, PEP 322 has been completely revised. The response was strongly positive, but almost everyone preferred having a function instead of multiple object methods. The...
15
by: Felix Kater | last post by:
Hi, in a given library I register callback functions with this function: bool set_callback(int index, int (*callback_function)(long)); I need the callback function to also pass the index...
23
by: Brian | last post by:
I am very new to C# programming and have run into a problem. I apologize for the repost of this article. For some reason, my news reader attached it to an existing thread. First off, I have...
3
by: Lenn | last post by:
Hello, I have the following example of AsyncCallback from a C# book which I wanted to implement in my project: //Class with AsyncDelegate public class AsyncProcess { public AsyncProcess() {
1
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej...
118
by: 63q2o4i02 | last post by:
Hi, I've been thinking about Python vs. Lisp. I've been learning Python the past few months and like it very much. A few years ago I had an AI class where we had to use Lisp, and I absolutely...
9
by: colin.mcnulty | last post by:
Hi, I'm a SQL Server DBA, but I guess that won't buy me any friends round here huh? ;-) I've been asked to look at the SQL that's being executed on a DB2 database from a web app, specifically...
6
by: Eric_Dexter | last post by:
Instead of creating my buttons and waiting for me to press them to execute they are executing when I create them and won't do my callback when I press them.. thanks for any help in advance ...
2
by: qwedster | last post by:
Folks! What is the difference between PostBack and Callback ( !IsPostBack and if(!IsCallback)) Like in the following Code Snippet: protected void Page_Load(object sender, EventArgs...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.