472,782 Members | 1,113 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,782 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 1711
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: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.