I have started working with ASP.NET controls and there appeared a question:
"why events in ASP controls are defined as delegates, and not as methods"?
Because an event must point to the function that it fires somehow and in C# this mechanism is achieved by delegates.
In response to the comment:
Then, why is such not a case with Java that uses only methods to fire
events?
Because Java uses the old traditional event pattern (like in C++). C# delegates are easier to use and also allow you to point to a static function rather than forcing the use of a class method.
Related
I'm fine-tuning a library written in java for android that deals with bluetooth, that I will use in a Xamarin project with native binding.
Since it deal with I/O, most of the api contains async method and, cause we don't have access to the good stuff yet (lambdas), those async calls are dealt using callbacks (an interface to be implemented by the client). ie :
void connect(BluetoothPeripheral target, IConnectionCompletion handler);
Of course in C#, there are much better way to deal with async stuff : Action instead of creating a whole new class, or even better the Task with async/await.
My question is : What do I need to do to map those Callback based java methods to C# methods that will return Task or take and Action instead of the callback?
When i working with one GWT project am using MVP pattern and HandlerManager for communicating on the application via Events. Now am implementing History Machanisam on my project.
They(GWT tearm) used Class EventBus for managing the events.
When read some blog i foud HandlerManger is used for Widgets and EventBus for other application wide communication.
But i feel both of them have same functionalities, then whats the purpose of this two implemetations, or whats the difference between them .
please help me
HandlerManager is the ancestor of the EventBus, which was extracted from (factored out of) it.
The main difference is that a HandlerManager has a source that it enforces on the events being dispatched to it, whereas EventBus can dispatch events with no source (fireEvent) or with a given dynamic source (fireEventFromSource). You can then attach handlers to the EventBus that will only be triggered for events from a given source.
Within widgets, you want to enforce that the event source is the widget. For a global application-wide event bus, you either want no source, or a source dynamically set for each event, as needed (RequestFactory uses it for its EntityProxyChange events so you can listen only to events related to a given kind of EntityProxy)
Note: the javadoc for HandlerManager discourages using it for an application-wide event bus.
I am developing a Standard EXE Project for sending mail.
I have a class module for sending email using winsock.
I have a withevents winsock variable set to the winsock control of a form.
The problem is that events are being catched in form's control event handler.
When i comment form's control event handling procedures and put a breakpoint in class module witheevents variable's event handler,i am unble to catch the events.
Please suggest a workaround.
If you really need to create a class (little c) that wraps constituent controls you create a UserControl, which can be invisible at runtime and have no UI interaction at all. Then, as the Winsock control's container, this UserControl will receive the events and you can handle them there.
I do this fairly often in order to create higher-level communication components, moving things like a message framing protocol inside. Then the container I put these UserControls onto only handles events raised when it has received complete messages for example. I've done the same thing to create an embeddable HTTP Server control, raising events back to the containing Form to process GET/POST requests with parameters and so on to provide a Web UI.
A Class (big C), Form, and UserControl are just three kinds of class (little c) you can create in VB6. "Class modules" really should have been called "UserClass" for clarity I suppose, in hindsight.
I'm not a solid GUI programmer, so I'm trying to understand different event architectures. I'm developing a system (in GWT, but I'm not sure that matters) where we are introducing a few custom events. In general, is it good practice to create an event and have the event fire itself onto to the event bus?
Following some articles and tutorials online, we have our controller code actually firing the events, but then each controller has to duplicate the code to fire the custom event. It seems that if you just put a fire() method on the event itself you can avoid that duplication.
What are the pros/cons of doing this?
In order to have an event fire itself, you'd need to inject the EventBus instance into the event when you create it. This means your controller (the one newing up the event) would have:
new MyEvent(m_eventBus).fire();
If you rework the code like this:
MyEvent event = new MyEvent();
m_eventBus.fireEvent(event);
then you wouldn't have to put any logic or references to services inside your Event instance, where it's not really needed. If you're using GWT, the HandlerManager class already implements an event bus for you.
Is there a way to handle the application_start "event" without using the global.asax?
The best I can come up with is an HttpModule that checks some static variable on every begin_request, which is INCREDIBLY wasteful :(
Do I have any other options?
Thanks
AFAIK, the reflection-based "pseudo-events" in Global.asax are not accessible in any other way than by reflection. However, for the application_start event, you might be able to achieve similar functionality by overriding the Init() method on a subclass of HttpApplication. Some functionality might not be accessible, as it probably fires on a slightly different point in the lifecycle.
Alternatively, if you're going with an HttpModule, couldn't you just use the Init() method instead of begin_request?
If your code is existing in the website, you can use the largely undocumented 'AppInitialize' method. Add this static method to any class in your web project.
(Note: it will not work if contained in a compiled assembly within the site.)
For more info, search for "AppInitialize". (Ex: http://www.bing.com/search?q=appinitialize+msdn&src=IE-SearchBox&FORM=IE9bSRC)