Event handling is a coding style about handling messages between a source and one or more subscribers. A point listener in the source provide a way which subscribed code can consume messages raised from the source.
Questions tagged [event-handling]
12746 questions
58
votes
3 answers
Forwarding events in C#
I'm using a class that forwards events in C#. I was wondering if there's a way of doing
it that requires less code overhead.
Here's an example of what I have so far.
class A
{
public event EventType EventA;
}
class B
{
A m_A = new A();
…

user3891
- 9,101
- 4
- 24
- 18
57
votes
4 answers
Should I always disconnect event handlers in the Dispose method?
I'm working in C# and my workplace has some code standards. One of them is that each event handler we connect (such as KeyDown) must be disconnected in the Dispose method. Is there any good reason for that?

No Idea For Name
- 11,411
- 10
- 42
- 70
55
votes
5 answers
jQuery .on() method doesn't see new elements
I'm getting a JSON element and building a list from its items like this:
getTitles: function(data) {
data = data || {};
var list = [];
$.getJSON(
'/titles',
data,
function(data) {
$.each(data.data,…

cnkt
- 2,943
- 5
- 30
- 43
55
votes
10 answers
button onclick function firing twice
I have a button that calls a javascript function using an event handler. For some reason, the event handler is being called twice.
Here is my button (I am using a php object to generate the code, that's why there are a lot of empty tags):
52
votes
8 answers
How to ensure an event is only subscribed to once
I would like to ensure that I only subscribe once in a particular class for an event on an instance.
For example I would like to be able to do the following:
if (*not already subscribed*)
{
member.Event += new…

Glen T
- 1,550
- 1
- 13
- 22
52
votes
2 answers
Accessing functions bound to event handlers with jQuery
With jQuery you can bind functions to an event triggered on a DOM object using .bind() or one of the event handler helper functions.
jQuery have to store this internally somehow and I wonder if is it possible given a DOM object, to find out which…

googletorp
- 33,075
- 15
- 67
- 82
51
votes
2 answers
What is the difference between the KeyCode and KeyData properties on the .NET WinForms key event argument objects?
The two key event argument classes KeyEventArgs and PreviewKeyDownEventArgs each have two properties, KeyCode and KeyData, which are both of the enumeration type Keys.
What is the difference between these two properties? Do the values in them ever…

Chris Ammerman
- 14,978
- 8
- 41
- 41
51
votes
6 answers
Raising C# events with an extension method - is it bad?
We're all familiar with the horror that is C# event declaration. To ensure thread-safety, the standard is to write something like this:
public event EventHandler SomethingHappened;
protected virtual void OnSomethingHappened(EventArgs e)
{ …

Ryan Lundy
- 204,559
- 37
- 180
- 211
50
votes
7 answers
How do I make an eventhandler run asynchronously?
I am writing a Visual C# program that executes a continuous loop of operations on a secondary thread. Occasionally when that thread finishes a task I want it to trigger an eventhandler. My program does that but the when the event handler is…

PICyourBrain
- 9,976
- 26
- 91
- 136
49
votes
6 answers
jQuery Multiple Event Handlers - How to Cancel?
I have two functions bound to a click event at two different times (using jQuery). The order in which they are fired is significant. They are firing in the correct order. The problem is, when the first function returns false, the second function…

Josh Stodola
- 81,538
- 47
- 180
- 227
49
votes
1 answer
How to use the GWT EventBus
I wonder how to use the EventBus or whether there are some better solutions to send an Event through the project.
Widget1 has a Button. Widget2 has a Label, that should change when I press the button. These widgets are in a…

Mark
- 7,507
- 12
- 52
- 88
49
votes
4 answers
-event- can only appear on the left hand side of += or -=
I have an event in a loop. I am trying to prevent the same method being added to an event more than once. I've implemented the add and remove accessors.
However, I get an error stating that:
ItemsProcessed can only appear on the left hand side of +=…
user76071
49
votes
10 answers
Raise event thread safely - best practice
In order to raise an event we use a method OnEventName like this:
protected virtual void OnSomethingHappened(EventArgs e)
{
EventHandler handler = SomethingHappened;
if (handler != null)
{
handler(this, e);
}
}
But what is…

Jérémie Bertrand
- 3,025
- 3
- 44
- 53
49
votes
6 answers
jQuery .on() method - passing argument to event handler function
I have the following script which does not work