473,799 Members | 3,085 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 (IProgressCallb ack callback)
{
for (int i = 0; i < 100; i++)
{
// do stuff
callback.SetPro gress(i);
}
}
}
....
MyCallBackImple mentation callback = new MyCallBackImple mentation;
Thing thing = new Thing();
thing.DoLongOpe ration(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.ProgressE vent += new ProgressEventHa ndler(Foo);
thing.DoLongOpe ration();

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 1130

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

Similar topics

8
3774
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 events. The callbacks specified by the subscriber will be called when the events get trigerred in a different thread. Each event has different kinds of data associated with it. To achieve this I have the following: // The following describes the...
2
6760
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 delegated to. The problem I have is the actual updating of the progress bar. I can understand passing a pointer through the ldata paramater in C++, but I can't find an example of what to do in C#. In all the examples using delegates that I have found,...
5
2250
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 controls that are associated with window handles? regards Tomaz
1
1654
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 using the DialogBox macro. If I remove the Progress Control from the form, the form displays appropriately. Is there something that needs to be done in addition to providing a callback
4
5736
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 file is finished uploading but am not sure how to do it while file is uploading. Some sample code would be welcomed with open arms. Thank You.
9
3272
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 problem occurs when i try to show a progress bar. The screen freezes. I know i'm not the first one to ask about it. but i'm looking
2
5746
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 py, the changes are lost. This happening too if I copy the zip module to modify it. Any solution?
5
1950
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 Windows Callback is to generalise our API so that it can be compatible with any other language e.g. C++. Using normal delegates will not help us since delegates is a VB.Net feature and any other language cant make a use of it. Could please
2
2186
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 update , I dont use a form unless i have two. This , creates either one of two problems. When i'm downloading asynchonously , the main thread exits!
0
9687
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10251
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10228
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10027
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6805
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5585
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4141
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3759
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2938
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.