Tag Info

Hot answers tagged

6

At this point, it is mostly a (pretty strong) convention. That is, it will be weird if you write a library that does not follow that convention. The Event Design Guidelines say: DO use object as the type of the first parameter of the event handler, and call it sender. However, you may note that current guidance says that you should not define your own ...


6

Promises were made to solve problems like this; they work really well in functional languages (I've personally used them extensively in Javascript, where curiously jQuery actually has the worst implementation of them - see this comparison). The weird thing about using promises is accepting that things are easier when you make everything use them. I will ...


4

It depends on the layering of the design. If "nodes" are all in the same layer conceptually, then I would prefer references over events, especially read-only references. References are simpler and easier to trace with static analysis tools: References can be read-only fields, whereas event fields are always mutable. A reference field refers to a single ...


3

Of the now partially outdated but still useful article from MSDN: "When to Use Delegates Instead of Interfaces (C# Programming Guide)", a few of the rules-of-thumb stand out: Use a delegate in the following circumstances: (3) The caller has no need to access other properties, methods, or interfaces on the object implementing the method. My ...


3

It is operating system specific. On Linux, the X11 server manage a tree of X-windows (a tree hierarchy of nested rectangular areas). So the X server knows which X-window is concerned by a mouse click. If you have access to a Linux + Xorg system, try the xev command. X11 might be replaced by Wayland in the future. Underneath, the X11 server program itself ...


3

Yes, I believe your assumption is correct. I also tried to write some (ugly) code to test this hypothesis: class MyClassWithEvent { public event Action Fired; void OnFired() { var d = Fired; if (d != null) d(); } } class MyClassSubscribing { void M() { } public void DoSubscribe(MyClassWithEvent mcwe) { mcwe.Fired += M; ...


2

Identifying the pattern. This pattern is actually pretty smart. In fact it's so useful that Microsoft has written a considerable and well liked library called Reactive Extensions to solve this using a technique called functional reactive programming. The pattern you're trying to name is called an Observable. It generalizes an IEnumerable fundamentally. You ...


2

I read a blog post on this a while ago: http://www.patrick-wied.at/blog/image-protection-on-the-web His approach is to use interlacing images instead of single, still-standing images. You'd split up the image into several fractions, for example in the form of stripes, and display them alternating very fast. That way, if you try to cap the screen, you will ...


1

If you're using Java, use Thread.interrupt - this is exactly the scenario that system was designed for. Otherwise, you'll need to look at what synchronisation primitives your language provides. If it has an Event synchronisation class, use that (periodically poll the event in the worker thread and terminate if it is fired, signal the event if the user ...


1

I'm not sure I understood your question, but with the introduction of generics you don't need anymore to write a custom eventhandler, but you can create a custom EventArgs... public event EventHandler<MyEventArgs> MyEvent; public class MyEventArgs : EventArgs { //your stuff here } if you really need a custom EventHandler you can write: public ...


1

I believe your best option is to permanently disconnect that particular computer from the Internet. That way, even if a program did capture your screen of log your keyboard, then it will not be able to send it anywhere as there's no connection. Of course, you should also disconnect from the network as well unless it's necessary to be connected and you are ...


1

What you are describing is a common issue in reactive programming. The idiom is for asynchronous code to produce a Future which acts as a rendezvous point for other code. The code that depends on the results uses call-backs (or call-forwards, depending on your point of view), which take the value as it will be produced in the future. With suitable language ...


1

Why shouldn't event listeners outlive the object that registered them? It seems like you are assuming event listeners should registered by methods of controls(if we take the GUI example) - or more precisely, methods by objects of classes that inherit the GUI toolkit's controls. That's not a necessity - you could, for example, use a specialized object for ...


1

An Event message is something that has just happened. You are notifying of the event that has just happened. A Command message is a message that expects something to be done. It may or may not expect a response. When to use what comes down to coupling and the difference will only emerge over time as the systems evolve. Favoring events over commands ...



Only top voted, non community-wiki answers of a minimum length are eligible