我有一堂课用来存储我的数据:
class Model
{
public int Progress{ get; set; }
}
第二类,我可以修改这些数据并通知订阅者有关更改:
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);
}
}
//...
}
和这样的:
class ProgressForm
{
Model model;
public ProgressForm()
{
model = new Model();
Copy.Changed+=new Changed(ShowProgress);
}
void ShowProgress()
{
progressBar1.value = model.Progress;
}
}
如何分别更改每个模型的数据并ProgressForm
在运行两个或多个实例时显示此数据Copy
?
Main()
{
Copy copy = new Copy();
copy.Start();
Copy copy2 = new Copy();
copy2.Start();
}