473,408 Members | 2,402 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,408 software developers and data experts.

Progress notification through Callback or Events?

Been wondering about this...
Which is better? (pseudocode - please don't grill me about semantics etc.)

public class Thing
{
public void DoLongOperation(IProgressCallback callback)
{
for (int i = 0; i < 100; i++)
{
// do stuff
callback.SetProgress(i);
}
}
}
....
MyCallBackImplementation callback = new MyCallBackImplementation;
Thing thing = new Thing();
thing.DoLongOperation(callback);

OR

public class Thing
{
public event ProgressEvent;
public void DoLongOperation()
{
for (int i = 0; i < 100; i++)
{
OnProgress(i);
}
}
}

Thing thing = new Thing();
thing.ProgressEvent += new ProgressEventHandler(Foo);
thing.DoLongOperation();

As far as I'm concerned, they achieve the same result. You will have more
control using the interface method, if you want to tell your "progress
consumer" other things than what the progress is (e.g. close a progress
window whenever you want, generally with the event method you would just
close the window when the progress is set to 100% or something - or get the
long operation to fire another event if it's Asynchronous). Although I
think the event based method is more in keeping with the whole .NET event
driven methodology and stuff.

While I'm on the subject, what do you think about the whole populating an
EventArgs style of object and passing it with your event - type-o-thing? I
suppose it depends on what you're up to, but sometimes just a couple of
plain old parameters would do. I generally use the former, for consistency,
but doesn't it take a while to create the object, populate it and destroy it
later?

Any thoughts would be greatly appreciated.
Thanks a million,

Adam
Nov 22 '05 #1
0 1111

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

Similar topics

8
by: Ash | last post by:
Hello all, I am hoping this is the appropriate newsgroup for a C++ interface design question. I am trying to design an interface for a subscriber to register/deregister handlers for various...
2
by: H Glenn Hatfield | last post by:
I know this has come up a couple of times on the group, but I'm still having trouble with it. I'm fine with creating the delegate and CopyFileEx declarations and the function which gets...
5
by: Tomaz Koritnik | last post by:
I have a worker thread doing some long calculation and I'd like to report progress (percent done,...). One easy way it to call Control.Invoke(). But is there another way of doing this without using...
1
by: Ziggy | last post by:
Please excuse this elementary question...but I am just dumb.... I have taken a simplistic Dialog Box and added a Progress Control. When I did that, my Dialog Box was no longer able to intialize...
4
by: Kenneth Keeley | last post by:
Hi, I have a page that uploads files to my server and I wish to display a "Please wait while uploading" page to the user while the file is uploading. I have been able to redirect the user once the...
9
by: esakal | last post by:
Hello, I'm programming an application based on CAB infrastructure in the client side (c# .net 2005) Since my application must be sequencally, i wrote all the code in the UI thread. my...
2
by: durumdara | last post by:
Hi! I want to check my zip file writings. I need some callback procedure to show a progress bar. Can I do that? I don't want to modify the PyLib module to extend it, because if I get another...
5
by: sajin | last post by:
Hi All.. We are using VB .Net 2005 for implementing an API. API needs to generate events. For this client wants us to use Windows Callback (delegate implementation). The intention of using...
2
by: giddy | last post by:
hi , I'm in a slight dilemma. I have an updater program that checks for pending updates and downloads them if the users chooses to. Since i dont need a windows form to check if there is an...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.