TownCube
TownCube

Reputation: 1310

C# event handing in single-threaded applications

I have a single threaded C# assembly (my client) that subscribes to multiple events using the same event handler (a short print statement). The emitter of the events (the server) is multi-threaded and therefore could fire two events simultaneously at my single-threaded client.

How does the .NET platform handle this? Does it queue the events? Does it drop an event that can't be processed because the event handler is already busy?

Background

I asked a previous question but judging by the clarification I needed to add I think I could do a much better job of abstracting my question to make it more general and useful to others.

Upvotes: 1

Views: 1399

Answers (1)

Jon Skeet
Jon Skeet

Reputation: 1499770

Events in C# and .NET don't naturally know about threads at all. They're just an extra encapsulation layer for delegates, basically. The handlers will be called on whichever thread the "event raiser" chooses to use. It could decide to fire each event handler on a separate thread... or it could use one separate thread to calls all handlers, one after another... or it could do that synchronously within its own "normal" thread.

Upvotes: 4

Related Questions