473,549 Members | 2,655 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Timer on form not affected by other thread with no error

Situation:

Timer1 on main form needs to be stopped during a thread action.

Programming in second thread:

timer1.enabled = false

Action:

1. No error
2. Timer is not stopped.

Well, thanks!

There is no .InvokeRequired available for a timer control
There is no error message
There is no action

What could be worse than nothing happening and no message saying it did
not happen? Oh, I know, a message saying "The action was not
performed." with no information about what action was not performed.

Yes, I fixed it by creating a global variable and setting it and having
the timer tick code look at the global variable to see if it should
proceed or exit. Very stupid and wasteful but, at least, it works.

There seems to be an idea that threads should not change global
variables which are to be viewed by code outside the thread but I see no
other way to proceed. Spawning a form would require the same global
because I don't want to use ShowDialog on it so the main thread UI will
continue to work.

Mike

Jun 27 '08 #1
2 994
Ju********@home .net wrote in news:nvjn04ljmi 00obv3ihrl31kl1 f6moqv14s@
4ax.com:
Timer1 on main form needs to be stopped during a thread action.

Programming in second thread:

timer1.enabled = false

Action:

1. No error
2. Timer is not stopped.
How are you getting a reference to the timer object?

The thread obviously needs to have access to the timer to stop it?

--
sp**********@ro gers.com (Do not e-mail)
Jun 27 '08 #2
Hi,

You know that there are 3 timers where the system.Threadin g.Timer is for
working with threads.

http://msdn2.microsoft.com/en-us/lib...ing.timer.aspx

Cor
<Ju********@hom e.netschreef in bericht
news:nv******** *************** *********@4ax.c om...
Situation:

Timer1 on main form needs to be stopped during a thread action.

Programming in second thread:

timer1.enabled = false

Action:

1. No error
2. Timer is not stopped.

Well, thanks!

There is no .InvokeRequired available for a timer control
There is no error message
There is no action

What could be worse than nothing happening and no message saying it did
not happen? Oh, I know, a message saying "The action was not
performed." with no information about what action was not performed.

Yes, I fixed it by creating a global variable and setting it and having
the timer tick code look at the global variable to see if it should
proceed or exit. Very stupid and wasteful but, at least, it works.

There seems to be an idea that threads should not change global
variables which are to be viewed by code outside the thread but I see no
other way to proceed. Spawning a form would require the same global
because I don't want to use ShowDialog on it so the main thread UI will
continue to work.

Mike
Jun 27 '08 #3

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

Similar topics

4
4016
by: Anthony Boudouvas | last post by:
Hi to all, i have a form with 2 System.Windows.Forms.Timer objects. One fire every 5 seconds and the other every 10 seconds, the both take actions in two hashtables declared in same form. When timers fire, main form is somewhat blocking until timers finish their job, (socket operations). (Imagine to move the form by it's caption bar and...
8
2768
by: Daniel P. | last post by:
I'm trying to set a timer that gets called every 3 seconds so I can update a field in the UI with the time elapsed since the process started. What am I doing wrong that timerDF_Tick does not get called? private System.Windows.Forms.Timer timerDF; this.timerDF = new System.Windows.Forms.Timer(this.components);
13
9721
by: Diego_Atos | last post by:
I've create a "stupid" animation. A simple label that bounce on borders of my form. Motion is ruled by a timer that set the timing of every steps. If I set the interval at "1000" it works properly, howevery if i set it at "10" or less, it warks slower than it would be. Anyone can help me?
6
2844
by: Dan | last post by:
I've created a pocketpc app which has a startup form containing a listview. The form creates an object which in turn creates a System.Threading.Timer. It keeps track of the Timer state using a TimerState object similar to the example in the System.Threading.Timer documentation. The method which handles the timer events, among other things,...
7
2663
by: Mike Eaton | last post by:
Hi All, I have a simple application that allows users to clock in and out and stores the data for use by the payroll department. It spends most of its life as a tray icon and when the user clicks on it, a clock-in/out form is displayed. My problem is this: I've added a timer to the main module to allow the user to set a time to be...
5
9862
by: Michael C# | last post by:
Hi all, I set up a System.Timers.Time in my app. The code basically just updates the screen, but since the processing performed is so CPU-intensive, I wanted to make sure it gets updated regularly; like every 1.5 secs. or so. I only ran into one issue - the MyTimer_Elapsed event handler was not updating the screen correctly all the time,...
4
3061
by: Nijazi Halimaji | last post by:
Hi everybody I have created a new timer object WithEvents tmr_check As New System.Timers.Timer On my form_Load-Event I activated the timer... Then I made a label on my form and putted on the Elapsed-Event of my timer object following code to change the Label.Text Label1.Text = "Ola"
5
3247
by: Peted | last post by:
Just some threading questions 1. in a MDI app if you have multiple child forms, does each child form run in its own thread ? Eg do you get error trying to update one control on form1 from form 2 2. if you have a timer control running on a childform, and you either a. minimize or
3
3829
by: Beemer Biker | last post by:
Unaccountably, I cannot re-enable a timer from an background thread. The disable works fine, I just cannot get it to start back up. There is no method "InvokeRequired" like there is for windows.forms.controls and I get no error message about cross thread so I am not sure where the problem is. I have a "SerialPoll_timer" that every second...
0
7541
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
7979
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
7826
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5385
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5107
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3512
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
3493
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1960
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
781
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.