How to handle EasyStorage events

Nov 10, 2009 at 8:16 AM
Edited Nov 10, 2009 at 8:18 AM

This question might be more a c# question, but its specifically for using EasyStorage and might be helpful to others so I'll ask it.

I want to deal with the device disconnected event. I want to call my own method called OnSharedSaveDevice_DeviceDisconnected() and to have EasyStorage do nothing (so no prompt). Is this the right way to do this, or is this attaching two separate responders to the event:

_sharedSaveDevice.DeviceDisconnected += (s, e) => e.Response = EasyStorage.SaveDeviceEventResponse.Nothing;

_sharedSaveDevice.DeviceDisconnected += (s, e) => OnSharedSaveDevice_DeviceDisconnected(s, e);

Having written this I think now I should be only using the second line above, and within that method OnSharedSaveDevice_DeviceDisconnected() I should set e.Reponse.  Is that correct?



Nov 10, 2009 at 2:38 PM

That is subscribing two event handlers to the disconnected event. You should only do one or the other. The first one would work or you could set e.Response in the OnSharedSaveDevice_DeviceDisconnected method.

The second line is actually a little redundant. If you're going to use the lambda expression (with the =>) you don't need to call a method. If you just wanted to hook up that method as an event handler, you can just do:

_sharedSaveDevice.DeviceDisconnected += OnSharedSaveDevice_DeviceDisconnected;

And save yourself some typing. :)


Nov 10, 2009 at 7:12 PM

Thanks SimReality, appreciated.