473,224 Members | 1,953 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,224 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 1271
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...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.