Global Variable problems with multithreading

N

Nathan

Somebody help please, I am desperate for help as I've
battled this problem for 3 days now! :(

I have an application (NT Service) that uses 2 threads...
one worker-thread (i.e. always running) and a 2nd thread
that is used to display a gui (NT service runs with
desktop interaction) on demand, i.e. from a Notify icon in
the toolbar.

I have an object, which uses a Timer
(system.timers.timer). I have a collection of these
objects globally defined.

My application is connected to a data-server which is
always sending data to me. For this reason, my worker-
thread must always be running, and I cannot drop the
connection to the server that is supplying me the data -
not even for 1 msec.

The problem I am having is that in some situations, a user
of my application may need to change the properties of my
objects.. they may need to change the timer to tick every
500msec or every 100msec for example. So my GUI thread
shows a property screen, and then sets the global object
properties to equal those defined within the screen, once
the screen is closed+validated.

When stepping through the application (debug mode) I can
see the global variable has indeed been changed, but when
I step through the timer.elapsed event (which is supposed
to be running in the worker-thread) I can see that the
properties of myself (the global object that contains this
timer) does not reflect the new settings.

I have placed breakpoints on my objects NEW constructors,
and they never fire... so I know I am now duplicating the
objects in memory.

The Timer seems to use its own thread regardless, and I
think this is where the problem lies. I think that there
is a mutexing problem which is causing my problems.

I have placed a Synclock on the global object while I
change the properties of it, after the user has closed the
properties screen... this DOES help, but only once! i.e.
if you change the timer setting from 100msec to 500msec,
this is reflected the first time, but subsequent attempts
at changing the properties do not get reflected. This is
the same code being executed, and there are no counters or
IF..THEN statements that would cancel out the properties
being set, because I can see them change when stepping
through the application.

If I re-open the properties window of the object, I do see
the correct object values.

When stepping through the timer, the properties of "me"
differ from what they should be.

Has anybody seen this? does anybody know what the problem
might be? Any help would be truly welcomed.
 
S

steve

is your object declared as "shared"...if not that may help also, are you
releasing the synclock after you modify the object's properties?


| Somebody help please, I am desperate for help as I've
| battled this problem for 3 days now! :(
|
| I have an application (NT Service) that uses 2 threads...
| one worker-thread (i.e. always running) and a 2nd thread
| that is used to display a gui (NT service runs with
| desktop interaction) on demand, i.e. from a Notify icon in
| the toolbar.
|
| I have an object, which uses a Timer
| (system.timers.timer). I have a collection of these
| objects globally defined.
|
| My application is connected to a data-server which is
| always sending data to me. For this reason, my worker-
| thread must always be running, and I cannot drop the
| connection to the server that is supplying me the data -
| not even for 1 msec.
|
| The problem I am having is that in some situations, a user
| of my application may need to change the properties of my
| objects.. they may need to change the timer to tick every
| 500msec or every 100msec for example. So my GUI thread
| shows a property screen, and then sets the global object
| properties to equal those defined within the screen, once
| the screen is closed+validated.
|
| When stepping through the application (debug mode) I can
| see the global variable has indeed been changed, but when
| I step through the timer.elapsed event (which is supposed
| to be running in the worker-thread) I can see that the
| properties of myself (the global object that contains this
| timer) does not reflect the new settings.
|
| I have placed breakpoints on my objects NEW constructors,
| and they never fire... so I know I am now duplicating the
| objects in memory.
|
| The Timer seems to use its own thread regardless, and I
| think this is where the problem lies. I think that there
| is a mutexing problem which is causing my problems.
|
| I have placed a Synclock on the global object while I
| change the properties of it, after the user has closed the
| properties screen... this DOES help, but only once! i.e.
| if you change the timer setting from 100msec to 500msec,
| this is reflected the first time, but subsequent attempts
| at changing the properties do not get reflected. This is
| the same code being executed, and there are no counters or
| IF..THEN statements that would cancel out the properties
| being set, because I can see them change when stepping
| through the application.
|
| If I re-open the properties window of the object, I do see
| the correct object values.
|
| When stepping through the timer, the properties of "me"
| differ from what they should be.
|
| Has anybody seen this? does anybody know what the problem
| might be? Any help would be truly welcomed.
 
G

Guest

Hey Steve,

Thanks for the reply.

The object is set as PUBLIC.
I synclock the object, then set its values, then release
the synclock.

The bizarre thing is that when doing this, the properties
do seem to get changed and observed by the timer... but
only the first time this is done, other times results in a
no-change.

Will "shared" be better than "public"?
 
S

steve

it should in this case b/c it won't be concerned about the object's
instancing. worth a try anyway before trying other fix tests.


| Hey Steve,
|
| Thanks for the reply.
|
| The object is set as PUBLIC.
| I synclock the object, then set its values, then release
| the synclock.
|
| The bizarre thing is that when doing this, the properties
| do seem to get changed and observed by the timer... but
| only the first time this is done, other times results in a
| no-change.
|
| Will "shared" be better than "public"?
|
| >-----Original Message-----
| >is your object declared as "shared"...if not that may
| help also, are you
| >releasing the synclock after you modify the object's
| properties?
| >
| >
| >| >| Somebody help please, I am desperate for help as I've
| >| battled this problem for 3 days now! :(
| >|
| >| I have an application (NT Service) that uses 2
| threads...
| >| one worker-thread (i.e. always running) and a 2nd thread
| >| that is used to display a gui (NT service runs with
| >| desktop interaction) on demand, i.e. from a Notify icon
| in
| >| the toolbar.
| >|
| >| I have an object, which uses a Timer
| >| (system.timers.timer). I have a collection of these
| >| objects globally defined.
| >|
| >| My application is connected to a data-server which is
| >| always sending data to me. For this reason, my worker-
| >| thread must always be running, and I cannot drop the
| >| connection to the server that is supplying me the data -
| >| not even for 1 msec.
| >|
| >| The problem I am having is that in some situations, a
| user
| >| of my application may need to change the properties of
| my
| >| objects.. they may need to change the timer to tick
| every
| >| 500msec or every 100msec for example. So my GUI thread
| >| shows a property screen, and then sets the global object
| >| properties to equal those defined within the screen,
| once
| >| the screen is closed+validated.
| >|
| >| When stepping through the application (debug mode) I can
| >| see the global variable has indeed been changed, but
| when
| >| I step through the timer.elapsed event (which is
| supposed
| >| to be running in the worker-thread) I can see that the
| >| properties of myself (the global object that contains
| this
| >| timer) does not reflect the new settings.
| >|
| >| I have placed breakpoints on my objects NEW
| constructors,
| >| and they never fire... so I know I am now duplicating
| the
| >| objects in memory.
| >|
| >| The Timer seems to use its own thread regardless, and I
| >| think this is where the problem lies. I think that there
| >| is a mutexing problem which is causing my problems.
| >|
| >| I have placed a Synclock on the global object while I
| >| change the properties of it, after the user has closed
| the
| >| properties screen... this DOES help, but only once! i.e.
| >| if you change the timer setting from 100msec to 500msec,
| >| this is reflected the first time, but subsequent
| attempts
| >| at changing the properties do not get reflected. This is
| >| the same code being executed, and there are no counters
| or
| >| IF..THEN statements that would cancel out the properties
| >| being set, because I can see them change when stepping
| >| through the application.
| >|
| >| If I re-open the properties window of the object, I do
| see
| >| the correct object values.
| >|
| >| When stepping through the timer, the properties of "me"
| >| differ from what they should be.
| >|
| >| Has anybody seen this? does anybody know what the
| problem
| >| might be? Any help would be truly welcomed.
| >
| >
| >.
| >
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top