473,395 Members | 1,696 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,395 software developers and data experts.

Events handling asking for comment

Re the example I code below.
I have tried to make a very consise example
of events / eventshandling;
would you please comment?

(Don't tell me to read a book.)

Thanks,
Zach.

using System;

namespace EventsHandlingTest
{
public class TestClass
{
public class MakeEventArgs:EventArgs
{
public readonly int counter;
public MakeEventArgs(int counter)
{
this.counter = counter;
}
public override string ToString()
{
return counter.ToString ();
}

}
public class Publish
{
public delegate void EventHandler(object action, MakeEventArgs dh);
public event EventHandler onLimit;
int limit = 100;
int number = 0;

public void generateEvents()
{
while(true)
{
if(number++ > limit-2)
{
MakeEventArgs dh = new MakeEventArgs(number);
onLimit(this,dh);
number = 0;
}
}
}
}

public class SubscribingClass
{
public void subscribe(Publish publish)
{
publish.onLimit += new
EventsHandlingTest.TestClass.Publish.EventHandler( publish_onLimit);
}

public void publish_onLimit(object publish, MakeEventArgs dh)
{
Console.WriteLine(dh.ToString());
}

}

static void Main()
{
Publish publish = new Publish();
new SubscribingClass().subscribe(publish);
publish.generateEvents();
}
}
}

Nov 17 '05 #1
1 1431
public readonly int counter;

This should be private.

Since no comment is forthcoming I will assume
the example to be correct (apart from the above).

Zach.

Nov 17 '05 #2

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

Similar topics

3
by: Trevor | last post by:
Hello, How can I setup an event in C#? I would like for class A to have an event, and class B to intercept the event. Class B should not be able to call the event itself, only class A. How is...
3
by: Stampede | last post by:
Hi, I want to use the FileSystemWatcher in a Windows Service. I read an article, where the author created the FileSystemWatcher object in a seperate thread and when the event is fired, he started...
12
by: scsharma | last post by:
Hi, I am working on creating a webapplication and my design calls for creating main webform which will have menu bar on left hand side and a IFrame which will contain all the forms that are shown...
4
by: Colin McGuire | last post by:
Hi again, thanks everyone for your previous help. But having resolved past problems, I'm moving on to new problems :( This one is a simple winforms application with two buttons, named Button1...
10
by: Anthony England | last post by:
(sorry for the likely repost, but it is still not showing on my news server and after that much typing, I don't want to lose it) I am considering general error handling routines and have...
4
by: | last post by:
Hi All, when you chain an event eg tb.Enter+= ; Is it possible to ensure I will get the first bite at the event and also is it possible to refuse access to this event lower down the chain. hope...
4
by: jehugaleahsa | last post by:
Hello: Is there a way to prevent one event from firing while another event is already being fired? I have a tool that extracts media from web pages and it has multiple events firing when the...
4
by: Joergen Bech | last post by:
I sometimes use delegates for broadcasting "StateChanged" events, i.e. if I have multiple forms and/or controls that need updating at the same time as the result of a change in a global/common...
7
by: zaphod42 | last post by:
funny thing....I'm dynamically building forms, well, WAS building forms, but for this project I need some very specific validation and logic handling, so while I was changing my functions to deal...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...

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.