How would you recommend I setup an event handler to fire when a variable is updated with a value > 0.
public _price;
public double GetPrice(string item)
{
_table.GetData += new EventHandler<EventArgs>(ExtractData);
// Right now I set it to sleep to give it enough time to return the data.
// But I would like to setup an eventhandler to return the _price when a value is populated
Thread.Sleep(1000);
return _price;
}
void ExtractData(object sender, DataEventArgs e)
{
foreach (PriceRecord rec in e)
{
if (rec.myprc != null)
{
_price = double.Parse(rec.myprc.Value.ToString());
}
}
}
If I remove Sleep it doesn't have enough time to get the data before returning an incorrect value. I would like to remove sleep to increase performance and just for my own knowledge. If there are better alternatives than using an event handler Im open to suggestions.
Any suggestions or advice you have is appreciated, Thank you.