473,385 Members | 1,676 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Managing data within events A and B, when event C fires

I have three events, using event handler methods as depicted below.
Two of those event handler methods need to reset specific data
whenever the other event left fires. I wasn't sure how to properly
implement that, is there a better way than using state management
variables for each timer as i'm doing in the outline below?

private string szProperty1 = null;
// updated by class consumer
public string Property1
{
get { return this.szProperty1; }
set { this.szProperty1 = value; }
}

// state management
private string szProperty1Last1 = null;
private string szProperty1Last2 = null;
private string szProperty1Last3 = null;

private string szProperty2 = null;
private string szProperty3 = null;

[interval: 100ms]
private void EventHandlerMethod1
{
// exit if szProperty1 == null or no event subscriptions
// if szPropertyLast1 != szProperty1, set szPropertyLast1 =
szProperty1, fire event
}

[interval: 100ms]
private void EventHandlerMethod2
{
// exit if szProperty1 == null or no event subscriptions
// if szPropertyLast2 != szProperty1, set szPropertyLast2 =
szProperty1, reset szProperty2, fire event
}

[interval: 500ms]
private void EventHandlerMethod3
{
// exit if szProperty1 == null or no event subscriptions
// if szPropertyLast3 != szProperty1, set szPropertyLast3 =
szProperty1, reset szProperty3, fire event
}
Jul 9 '08 #1
6 1279
On Tue, 08 Jul 2008 21:00:01 -0700, kirk <ki****@gmail.comwrote:
I have three events, using event handler methods as depicted below.
Two of those event handler methods need to reset specific data
whenever the other event left fires. I wasn't sure how to properly
implement that, is there a better way than using state management
variables for each timer as i'm doing in the outline below?
Hard to say without knowing what you're really doing. Typos aside, My
biggest concern would be the question of whether these events can each be
raised on different threads. If they can, then you need some
synchronization to ensure that when one handler is inspecting and reacting
to the state of the szProperty1 value, the other isn't changing it
(otherwise, you might miss a state transition).

Other than that, without additional information, seems fine to me. :)

Pete
Jul 9 '08 #2
On Jul 9, 8:00*am, kirk <kir...@gmail.comwrote:
I have three events, using event handler methods as depicted below.
Two of those event handler methods need to reset specific data
whenever the other event left fires. *I wasn't sure how to properly
implement that, is there a better way than using state management
variables for each timer as i'm doing in the outline below?

private string szProperty1 = null;
// updated by class consumer
public string Property1
{
* *get { return this.szProperty1; }
* *set { this.szProperty1 = value; }

}

// state management
private string szProperty1Last1 = null;
private string szProperty1Last2 = null;
private string szProperty1Last3 = null;

private string szProperty2 = null;
private string szProperty3 = null;

[interval: 100ms]
private void EventHandlerMethod1
{
* *// exit if szProperty1 == null or no event subscriptions
* *// if szPropertyLast1 != szProperty1, set szPropertyLast1 =
szProperty1, fire event

}

[interval: 100ms]
private void EventHandlerMethod2
{
* *// exit if szProperty1 == null or no event subscriptions
* *// if szPropertyLast2 != szProperty1, set szPropertyLast2 =
szProperty1, reset szProperty2, fire event

}

[interval: 500ms]
private void EventHandlerMethod3
{
* *// exit if szProperty1 == null or no event subscriptions
* *// if szPropertyLast3 != szProperty1, set szPropertyLast3 =
szProperty1, reset szProperty3, fire event

}
Do you really need to do those resets in the event handlers? Couldn't
you do it in Property1.set immediately as soon as it is set?

Even if so, I would change your code to three bool flags - one per
event handler - and set them in Property1.set, then check them (rather
than comparing old/new property value) in event handlers. That way
you'll avoid repeated string comparisons.
Jul 9 '08 #3
On Jul 9, 1:00*am, "Peter Duniho" <NpOeStPe...@nnowslpianmk.com>
wrote:
On Tue, 08 Jul 2008 21:00:01 -0700, kirk <kir...@gmail.comwrote:
I have three events, using event handler methods as depicted below.
Two of those event handler methods need to reset specific data
whenever the other event left fires. *I wasn't sure how to properly
implement that, is there a better way than using state management
variables for each timer as i'm doing in the outline below?

Hard to say without knowing what you're really doing. *Typos aside, My *
biggest concern would be the question of whether these events can each be*
raised on different threads. *If they can, then you need some *
synchronization to ensure that when one handler is inspecting and reacting *
to the state of the szProperty1 value, the other isn't changing it *
(otherwise, you might miss a state transition).

Other than that, without additional information, seems fine to me. *:)

Pete
Thanks Pete.

This is single threaded, so no sync issues that I can see. Basically
this is for a RAS tool i'm creating. The first event fires if a class
consumer changes the name of the RAS entry to use in the phone book.
The second event fires if the state of that RAS entry changes and the
third event fires if the statistics on that RAS entry changes. So,
what i'm trying to do is enforce cleanup in the latter two events, to
avoid tracking old state and statistics data, if the RAS entry were to
ever change. I had two thoughts for other options, let the first
event do the cleanup for the state information on the latter two
events, which looks susceptible to the RAS entry changing before the
first event would catch it and the latter two would use it, tracking
old info. Or I don't know if it's possible, but had another idea of
inter-event processing, where I could subscribe the latter two events
to the first event.
Jul 9 '08 #4
On Jul 9, 7:07*am, Pavel Minaev <int...@gmail.comwrote:
On Jul 9, 8:00*am, kirk <kir...@gmail.comwrote:


I have three events, using event handler methods as depicted below.
Two of those event handler methods need to reset specific data
whenever the other event left fires. *I wasn't sure how to properly
implement that, is there a better way than using state management
variables for each timer as i'm doing in the outline below?
private string szProperty1 = null;
// updated by class consumer
public string Property1
{
* *get { return this.szProperty1; }
* *set { this.szProperty1 = value; }
}
// state management
private string szProperty1Last1 = null;
private string szProperty1Last2 = null;
private string szProperty1Last3 = null;
private string szProperty2 = null;
private string szProperty3 = null;
[interval: 100ms]
private void EventHandlerMethod1
{
* *// exit if szProperty1 == null or no event subscriptions
* *// if szPropertyLast1 != szProperty1, set szPropertyLast1 =
szProperty1, fire event
}
[interval: 100ms]
private void EventHandlerMethod2
{
* *// exit if szProperty1 == null or no event subscriptions
* *// if szPropertyLast2 != szProperty1, set szPropertyLast2 =
szProperty1, reset szProperty2, fire event
}
[interval: 500ms]
private void EventHandlerMethod3
{
* *// exit if szProperty1 == null or no event subscriptions
* *// if szPropertyLast3 != szProperty1, set szPropertyLast3 =
szProperty1, reset szProperty3, fire event
}

Do you really need to do those resets in the event handlers? Couldn't
you do it in Property1.set immediately as soon as it is set?

Even if so, I would change your code to three bool flags - one per
event handler - and set them in Property1.set, then check them (rather
than comparing old/new property value) in event handlers. That way
you'll avoid repeated string comparisons.- Hide quoted text -

- Show quoted text -
Thanks Pavel.

I thought of doing everything from the Property1.set as you
recommended. My fear, as I typically have is of guaranteeing an
atomic update before a timeslice is given to the timer(eventhandler).
For example, user says, update RAS entry name property, Property1.set
updates that single value, and before it gets to the resets, a
timeslice intervenes and executes the eventhandler. At that point the
eventhandler would be tracking old data, on a new property.

Maybe the better route, is to at the start of Property1.set, disable
the timers if they are running, update the variables, then restart the
timers if previously running?
Jul 9 '08 #5
On Jul 10, 3:39*am, kirk <kir...@gmail.comwrote:
I thought of doing everything from the Property1.set as you
recommended. *My fear, as I typically have is of guaranteeing an
atomic update before a timeslice is given to the timer(eventhandler).
For example, user says, update RAS entry name property, Property1.set
updates that single value, and before it gets to the resets, a
timeslice intervenes and executes the eventhandler. *At that point the
eventhandler would be tracking old data, on a new property.
What kind of timers do you use - System.Windows.Forms.Timer?
System.Threading.Timer? System.Timers.Timer? The first one won't ever
call an event handler on a different thread, so the situation you
describe simply cannot arise. It is possible for the last two, though.

Anyway, if your handlers are in fact called on a separate thread, then
you just need to use "lock" (or any other convenient synchronization
primitive) as needed to synchronize with any call to Property1.set
that may be in progress.
Jul 10 '08 #6
On Jul 10, 5:14*am, Pavel Minaev <int...@gmail.comwrote:
On Jul 10, 3:39*am, kirk <kir...@gmail.comwrote:
I thought of doing everything from the Property1.set as you
recommended. *My fear, as I typically have is of guaranteeing an
atomic update before a timeslice is given to the timer(eventhandler).
For example, user says, update RAS entry name property, Property1.set
updates that single value, and before it gets to the resets, a
timeslice intervenes and executes the eventhandler. *At that point the
eventhandler would be tracking old data, on a new property.

What kind of timers do you use - System.Windows.Forms.Timer?
System.Threading.Timer? System.Timers.Timer? The first one won't ever
call an event handler on a different thread, so the situation you
describe simply cannot arise. It is possible for the last two, though.

Anyway, if your handlers are in fact called on a separate thread, then
you just need to use "lock" (or any other convenient synchronization
primitive) as needed to synchronize with any call to Property1.set
that may be in progress.
Thank you for the additional information Pavel as well as your
patience with my lack of event driven coding. I am using
System.Windows.Forms.Timer, so I should be just fine as each event
will execute one at a time E2E as it drains through the common queue.
Knowing this, and the fact that the Property1 setter method only
executes via an event, i.e. is atomic, I am going to shift all cleanup
code there, as you originally suggested.
Jul 11 '08 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Tom | last post by:
Hi, In the following code I have reproduced a problem in IE that is extremely annoying for my application. <html> <head> <script type="text/javascript">
14
by: JPRoot | last post by:
Hi I use the following syntax to have events inherited from base to child classes which works nicely (virtual and override keyword on events). But I am wondering if it is a "supported" way of using...
2
by: David Veeneman | last post by:
I want to data bind a user control and a business object, using a BindingSource control. The control has a 'Priority' property that takes a 'Priority' enum (High, Normal, Low). The business object...
30
by: Charles Law | last post by:
Here's one that should probably have the sub-heading "I'm sure I asked this once before, but ...". Two users are both looking at the same data, from a database. One user changes the data and...
0
by: bob | last post by:
Hi all, I'm having a hard time figuring out the ORDER that the events in the DataGridView control fire in, and also determining exactly WHEN each event fires. The documentation seems to have...
3
by: cyber0ne | last post by:
I'm designing a basic form for data entry into one main table. There are two fields in the table that I would like to be automatically populated, not user-entered, when the record is posted. ...
4
by: Dave | last post by:
I have a global.asax file with Application_Start defined and create some static data there and in another module used in the asp.net application and I realize that static data is shared amongst...
5
by: Sin Jeong-hun | last post by:
class Manager { public event ItemEventHandler ItHappened; public Manager { Item i; i.ItHappend+=new ItemEventHandler(OnItHappened); } void OnItHappened(...) {
0
by: db007 | last post by:
I have a problem at the moment with a web project. I have two Panels within an UpdatePanel on an aspx page (using Masterpages). I'm using ASP.Net 2.0 with an AJAX enabled website. The two...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.