473,546 Members | 2,289 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Global Variable problems with multithreading

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+validate d.

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.
Nov 20 '05 #1
3 2391
is your object declared as "shared"... if not that may help also, are you
releasing the synclock after you modify the object's properties?
"Nathan" <np*****@softwa retoolbox.com> wrote in message
news:08******** *************** *****@phx.gbl.. .
| 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+validate d.
|
| 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.
Nov 20 '05 #2
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 youreleasing the synclock after you modify the object's properties?

"Nathan" <np*****@softwa retoolbox.com> wrote in message
news:08******* *************** ******@phx.gbl. ..
| 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+validate d.
|
| 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.
.

Nov 20 '05 #3
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.
<an*******@disc ussions.microso ft.com> wrote in message
news:07******** *************** *****@phx.gbl.. .
| 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?
| >
| >
| >"Nathan" <np*****@softwa retoolbox.com> wrote in message
| >news:08******* *************** ******@phx.gbl. ..
| >| 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+validate d.
| >|
| >| 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.
| >
| >
| >.
| >
Nov 20 '05 #4

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

Similar topics

12
5859
by: David WOO | last post by:
Hi, I am a newbie on C++, I need to define some global variables which should be accessible to most classes. In the mean time, I don't won't the global variables be modified freely at most of these classes. I know there is a pattern called singleton can more or less do such a trick. I am wondering is this the best way to do it (regarding...
2
1545
by: Gianguz | last post by:
I'd like to discuss about the opportunity to have a global objects creator that introduces into a general framework (suited for multithreading) a controlled semantic to manage globals variables (objects and scalar-types). In the following example Global is able to create objects of any kind with and index value attached to. So a Global<0,...
24
2503
by: LP | last post by:
After a code review one coworker insisted that global are very dangerous. He didn't really give any solid reasons other than, "performance penalties", "hard to maintain", and "dangerous". I think that I am using them appropriate in class in question. One typical example: This class initiates TCP session, keeps sending commands to the server...
11
1723
by: Trapulo | last post by:
I've a question about globa variables lifetime in an asp.net app. I've declared this class: Public Class Utils Private Shared _FcdDataManagement As FCD.DataManagement Public Shared ReadOnly Property FcdDataManagement() As FCD.DataManagement Get
8
1798
by: Morpheus | last post by:
Hello, Say I have a class with a member... char mId; Whenever an object is created, I want to assign an incrementing character to this member, for instance the first would be A, then B, C, D, E etc....
37
2712
by: eoindeb | last post by:
Sorry to ask another global variable question, but from reading other posts I'm still not sure whether to use them or not. I have a program with a set function that calls 4 other functions in order - let's say function A, B, C, D. It always calls function A first which is a function that returns a system path. Now all other functions...
9
8627
by: CDMAPoster | last post by:
About a year ago there was a thread about the use of global variables in A97: http://groups.google.com/group/comp.databases.ms-access/browse_frm/thread/fedc837a5aeb6157 Best Practices by Kang Su Gatlin, casual mention was made about using static variables as an alternative to using global variables. This caused me to think of the...
5
11802
by: Sandman | last post by:
I dont think I understand them. I've read the section on scope in the manual inside out. I'm running PHP 5.2.0 Here is the code I'm working on: //include_me.php <?php $MYVAR = array(); global $MYVAR, $a; ?>
1
29321
weaknessforcats
by: weaknessforcats | last post by:
C++: The Case Against Global Variables Summary This article explores the negative ramifications of using global variables. The use of global variables is such a problem that C++ architects have called it polluting the global namespace. This article explores what happens when the global namespace becomes polluted and how to avoid this...
0
7504
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7435
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7694
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7947
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6026
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3491
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3470
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1046
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
747
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.