hello I wonder why this code make me an exception.
namespace Test_Inotify
{
class Test_Onchange
{
private int value;
private object _lock = new object();
/*removed private object _lock;*/
public event System.EventHandler ValueChanged;
protected virtual void OnValueChange()
{
lock (_lock)
{
if (ValueChanged != null)
ValueChanged(this, EventArgs.Empty);
}
}
public int Value
{
get { return this.value; }
set
{
this.value = value;
OnValueChange();
}
}
}
}
And the form
namespace Test_Inotify
{
public partial class Form1 : Form
{
Test_Onchange ValueClass ;//ForceValue removed;
public Form1()
{
InitializeComponent();
/* Test_Onchange removed*/ ValueClass = new Test_Onchange();
ValueClass.ValueChanged += new EventHandler(EventValueChanged);
for (int i = 0; i < 10; i++)
{
Random Rndvalue = new Random();
int RandVal = Rndvalue.Next(0, 100);
ValueClass.Value = RandVal;
System.Threading.Thread.Sleep(500);
}
}
private void EventValueChanged(object sender, EventArgs e)
{
int valueforce = ValueClass.Value; /*removedForceClass.Value;*/
MessageBox.Show("Event raised"+valueforce);
}
}
}
I think it's in the EventValueChanged.... but I don't modify anything in the values, I only copy it in a local variable.
Could anyone help me??