I developing application using backround processes and MVP pattern.
Can I store states of processes (isCanceled, isStarted or isPaused) in ModelProcess (Model) like this:
public event EventHandler CancelChanged;
bool isCanceled = false;
public bool IsCanceled
{
get { return isCanceled; }
set
{
isCanceled = value;
if (isCanceled)
{
if (CancelChanged != null)
{
CancelChanged(this, EventArgs.Empty);
}
}
}
}
Your setter will only call
CancelChangedifisCanceledis being set totrue, no matter if it has beenfalsebefore. The following code will check if there is an actual change of the value, wich makes it idempotent.