By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,190 Members | 1,412 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,190 IT Pros & Developers. It's quick & easy.

How to properly manage state in events A and B, when event C fires

P: n/a
I have three events that I have created and manage with timers. Two
of the timer event handlers, the last two in the code below, need to
reset state management data, if the first event handler fires. My
question, is what I have implemented the right way to design state
management, or is there maybe a best practice to design this
differently?

private string szData1 = null;
public string Data1
{
get { return this.szData1; }
set { this.szData1 = value; }
}

private string szData2 = null;
private string szData3 = null;

// state management
private string szData1Last = null;
private string szData2Last = null;
private string szData3Last = null;
[interval: 100ms]
private void EventHandlerMethod1
{
// if szData1 != null and there are subscriptions, proceed
// if szData1Last != szData1, set szData1Last = szData1, fire event
}
[interval: 100ms]
private void EventHandlerMethod2
{
// if szData1 != null and there are subscriptions, proceed
// if szData2Last != szData1, set szData2Last = szData1, reset
szData2 value, fire event
}

[interval: 500ms]
private void EventHandlerMethod3
{
// if szData1 != null and there are subscriptions, proceed
// if szData3Last != szData1, set szData3Last = szData1, reset
szData3 value, fire event
}
Jul 9 '08 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.