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

event vs. delegate vs. threads

Hello,
what is the difference between "event" and the only use of delegate? Why
one should note events with "event" keyword when the functionality seems the
same as with pure delegates?

When I call some delegate, in which thread this delegate gets called -
callers = synchronous, or some other thread = asynchronous? And in what
thread is this done with "event"?

Ondra.

Nov 15 '05 #1
6 4807
Hello Ondrej,
what is the difference between "event" and the only use of delegate? Why
one should note events with "event" keyword when the functionality seems the same as with pure delegates?
This improves code readability. A notion of event is much more
understandable.
Then, it is more convenient to raise events than to invoke delegates.
When I call some delegate, in which thread this delegate gets called -
callers = synchronous, or some other thread = asynchronous? And in what
thread is this done with "event"?
In both cases, calls are synchronous, unless you use BeginInvoke.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"Ondrej Sevecek" <on***@sevecek.com.thisisanuntispamsuffix> wrote in message
news:eu****************@TK2MSFTNGP09.phx.gbl... Hello,
what is the difference between "event" and the only use of delegate? Why
one should note events with "event" keyword when the functionality seems the same as with pure delegates?

When I call some delegate, in which thread this delegate gets called -
callers = synchronous, or some other thread = asynchronous? And in what
thread is this done with "event"?

Ondra.


Nov 15 '05 #2
Ondra,

With events, the firing of the event is restricted to the class that
defined the event. This is a good thing, because if you just exposed a
public field that was a delegate, then anyone could invoke the delegate, and
you would have undesirable behavior.

When you call an event or a delegate synchronously, the event handlers
execute on whatever thread the delegate was invoked on. When you call it
asynchronously, the call will be executed on a thread other than the thread
that initiated the call.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Ondrej Sevecek" <on***@sevecek.com.thisisanuntispamsuffix> wrote in message
news:eu****************@TK2MSFTNGP09.phx.gbl...
Hello,
what is the difference between "event" and the only use of delegate? Why
one should note events with "event" keyword when the functionality seems the same as with pure delegates?

When I call some delegate, in which thread this delegate gets called -
callers = synchronous, or some other thread = asynchronous? And in what
thread is this done with "event"?

Ondra.

Nov 15 '05 #3
"Ondrej Sevecek" <on***@sevecek.com.thisisanuntispamsuffix> wrote in message
news:eu****************@TK2MSFTNGP09.phx.gbl...
Hello,
what is the difference between "event" and the only use of delegate? Why
one should note events with "event" keyword when the functionality seems the same as with pure delegates?
Behind the scenes, the functionality is pretty much the same. The delegate
is a bit more flexible, as you can hook multiple handlers in to create
multi-casting "events".
When I call some delegate, in which thread this delegate gets called -
callers = synchronous, or some other thread = asynchronous? And in what
thread is this done with "event"?


Unless you code it otherwise, the default is synch.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

************************************************** ********************
Think Outside the Box!
************************************************** ********************
Nov 15 '05 #4
Ondrej,
In addition to the others comments:

The way I view it is:

Events are implemented in terms of a Delegate, similar to how a Property is
implemented in terms of a Field.

The Event protects the underlying Delegate, similar to how a Property
protects the underlying Field.

In other words you use Events when you want to encapsulate the Delegate,
similar to how you use a Property when you want to encapsulate a Field.

Hope this helps
Jay

"Ondrej Sevecek" <on***@sevecek.com.thisisanuntispamsuffix> wrote in message
news:eu****************@TK2MSFTNGP09.phx.gbl...
Hello,
what is the difference between "event" and the only use of delegate? Why
one should note events with "event" keyword when the functionality seems the same as with pure delegates?

When I call some delegate, in which thread this delegate gets called -
callers = synchronous, or some other thread = asynchronous? And in what
thread is this done with "event"?

Ondra.

Nov 15 '05 #5
Properties are methods, not fields.
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:uM**************@TK2MSFTNGP12.phx.gbl...
Ondrej,
In addition to the others comments:

The way I view it is:

Events are implemented in terms of a Delegate, similar to how a Property is implemented in terms of a Field.

The Event protects the underlying Delegate, similar to how a Property
protects the underlying Field.

In other words you use Events when you want to encapsulate the Delegate,
similar to how you use a Property when you want to encapsulate a Field.

Hope this helps
Jay

"Ondrej Sevecek" <on***@sevecek.com.thisisanuntispamsuffix> wrote in message news:eu****************@TK2MSFTNGP09.phx.gbl...
Hello,
what is the difference between "event" and the only use of delegate? Why one should note events with "event" keyword when the functionality seems

the
same as with pure delegates?

When I call some delegate, in which thread this delegate gets called -
callers = synchronous, or some other thread = asynchronous? And in what
thread is this done with "event"?

Ondra.


Nov 15 '05 #6
Alvin,
Did you read what I stated? Did you understand what I said?

No place did I state a Property IS A Field, I made an analogy relating a
property to a field, however that is relating not stating is a!

I know properties are methods. It happens to be a method that normally
encapsulates a field.

Hope this helps
Jay

"Alvin Bruney" <alvin.bruney@.telia..com.> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Properties are methods, not fields.
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:uM**************@TK2MSFTNGP12.phx.gbl...
Ondrej,
In addition to the others comments:

The way I view it is:

Events are implemented in terms of a Delegate, similar to how a Property

is
implemented in terms of a Field.

The Event protects the underlying Delegate, similar to how a Property
protects the underlying Field.

In other words you use Events when you want to encapsulate the Delegate,
similar to how you use a Property when you want to encapsulate a Field.

Hope this helps
Jay

"Ondrej Sevecek" <on***@sevecek.com.thisisanuntispamsuffix> wrote in

message
news:eu****************@TK2MSFTNGP09.phx.gbl...
Hello,
what is the difference between "event" and the only use of delegate? Why one should note events with "event" keyword when the functionality seems
the
same as with pure delegates?

When I call some delegate, in which thread this delegate gets

called - callers = synchronous, or some other thread = asynchronous? And in what thread is this done with "event"?

Ondra.



Nov 15 '05 #7

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

Similar topics

1
by: Jerry J | last post by:
I'm trying to understand how many threads are involved when a client event handler is called. I am using a simple .net windows application. I click a button on a form that triggers an event. ...
3
by: James Dunkerley | last post by:
Hi, I am trying to create a class which downloads a web page in the background and then raises an event in the original thread in which it was created. This class is going to be the basis of a...
4
by: Bob Rock | last post by:
Hello, I was wondering if callback delegates, called in response to a event, are executed in their own thread. I was suspecting the OS might spawn a new thread and have the delegate execute in...
3
by: Koji Ishii | last post by:
I have a worker thread, and the thread needs to listen to WinForms Control's SizeChanged event. Here's my code. Control c = ...; if (c.InvokeRequired) { c.BeginInvoke(===don't know how to write...
6
by: Dan | last post by:
I've created a pocketpc app which has a startup form containing a listview. The form creates an object which in turn creates a System.Threading.Timer. It keeps track of the Timer state using a...
20
by: Bob Day | last post by:
Using VS 2003, VB, MSDE... There are two threads, A & B, that continously run and are started by Sub Main. They instantiationsl of identical code. Thread A handles call activity on telephone...
2
by: Paul E. Orman | last post by:
I have a piece of VB code (.NET 1.1 - VB 2003) that loads data from a database through a timer. So the timer is setup and from it I call the procedure that loads the latest records from the...
6
by: utkarsh | last post by:
Hi All, I am using the following method "FireAsync" (i got the following information from the google groups) to fire the event for all the subscribers. Is there another way to fire the event...
8
by: Brad Walton | last post by:
Hello. First post, but been doing a bit of reading here. I am working on a project in Java, but decided to switch over to C# after seeing some of the additional features I can get from C#. One of...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.