What is the most efficient way to create an undo event in a C # program that crunches a large data set in a loop in a separate thread?
Currently, I just use a cancel event that fires from my user interface thread, which subsequently calls the onCancel function on the number crunch thread. This undo function sets the variable "true", which is periodically checked by the crunch contour, for example
Class Cruncher {
private bool cancel = false;
public cruncher()
{
crunch();
}
private void crunch()
{
while(conditions AND !cancel) { crunch; }
dispose_resources;
}
private void onCancel()
{
cancel = true;
}
}
Until I check the cancel variable as often as my example above (and actually does not cancel the NOT), I would still like to optimize this crunch method as much as possible. Any examples where this is done more efficiently would be very nice to see.