|
-
Nov 10th, 2010, 11:50 AM
#1
Thread Starter
Not NoteMe
Event handlers
I'm using a class defined in an external library that allows access to a generic save device.
This class has an event handler for when it aquired the device.
I can then use the device to save/load, providing the device has been aquired.
I want to write an extension method that will perform a given method on the device if it's been aquired, and if it hasn't it will aquire it then perform the given method.
A first attempt as below:
Code:
public delegate void PostAquireDeviceAction();
public static void AquireDevicePerformAction(this SaveDevice saveDevice, PostAquireDeviceAction callMethod)
{
if (!saveDevice.HasValidStorageDevice)
{
saveDevice.PromptForDevice();
saveDevice.DeviceSelected += (sender, eventargs) =>
{
callMethod();
};
}
else
{
callMethod();
}
}
The issue with this is after calling this method, if the device is aquired again, that method will get called again (since it's a handler for the event).
How can i get round this issue?
Quotes:
"I am getting better then you guys.." NoteMe, on his leet english skills.
"And I am going to meat her again later on tonight." NoteMe
"I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
"my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
Have I helped you? Please Rate my posts. 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|