I have one class where I store my data:
class Model
{
public int Progress{ get; set; }
}
Second class where I can modify this data and notify subscribers about changes:
class Copy
{
//...
public static event EventHandler Changed;
Model model = new Model();
ProgressForm progressForm = new ProgressForm();
public void Start()
{
for(int i=0;i<100;i++)
{
model.Progress++;
if(Changed!=null)
Changed(this,EventArgs.Empty);
}
}
//...
}
and something like this:
class ProgressForm
{
Model model;
public ProgressForm()
{
model = new Model();
Copy.Changed+=new Changed(ShowProgress);
}
void ShowProgress()
{
progressBar1.value = model.Progress;
}
}
How can I change data for each model separately and show this data in ProgressForm when I run two or more instances of Copy?
Main()
{
Copy copy = new Copy();
copy.Start();
Copy copy2 = new Copy();
copy2.Start();
}
1 Answer