In this example I want to add a .loop({quantity},{sleepvalue})
to a method
I got it to work with this:
this.loop(count, 500,
()=>{
var image = Screenshots.getScreenshotOfDesktop();
pictureBox.load(image);
images.Add(image);
updateTrackBar();
});
using this extension method:
public static void loop(this Object _object, int count, int delay, MethodInvoker methodInvoker)
{
for(int i=0; i < count; i++)
{
methodInvoker();
_object.sleep(delay);
}
}
which means that the invocation syntax is:
this.loop(15,500, () => {...code...});
but ideally what I wanted to do was something like:
()=> { ...code...}.loop(10,500);
which doesn't work unless I do it like this:
new MethodInvoker(()=>{...code...}).loop(10,500);
which will work with this version of the extension method:
public static void loop(this MethodInvoker methodInvoker, int count, int delay)
{
for(int i=0; i < count; i++)
{
methodInvoker();
Processes.Sleep(delay);
}
}