Svish
Svish

Reputation: 158051

Event handling on in the .Net Micro Framework

I'm wondering if anyone has some pointers and/or a good guide on how to properly do events in the .Net Micro Framework.

I've gotten a Netduino and is playing around making a small wrapper framework around various components and I'm trying to make it sort of event driven. Started doing it the way I'm used to, but discovered there were several classes and interfaces in the Microsoft.SPOT namespace which seems event related, and I haven't used any of them before. For example:

And several more. How do I use all these properly? Should I use them?

As an example I'd like to create a wrapper around a photo/light sensor which raises an event whenever the light level changes. For this (I suppose?) I need to poll the value of an analog pin and see if it changes. I can do that pretty simply by firing off an observer on a separate thread or something like that. But is there an other way I should do this? I guess for example that I shouldn't have a thread per sensor as that could become quite many and the resources are pretty limited here?

Upvotes: 1

Views: 1105

Answers (1)

Paul Fryer
Paul Fryer

Reputation: 9527

Use events just like you would in other .net versions.

Declare and use events.

Declare and use delegates if you have a custom method signature you want your subscriber to use.

Build custom event arguments if you want to follow the (sender, args) pattern, etc.

Subscribe/unsubscribe to events with an event handler or inline function.

Bottom line is there is nothing special about micro framework events. You have all the stuff you have in the other versions, so just focus on making a good api for your consumers with events like you typically would.

Upvotes: 1

Related Questions