Click here to Skip to main content
15,890,995 members
Everything / Timer

Timer

timer

Great Reads

by Mehedi Shams
Word-making game!
by Peter Huber SG
How to correct the problem that the DispatcherTimer raises the Tick events slower than required by Interval
by Rick York
A simple, header-only class for high resolution timing
by Emiliano Musso
How to create a Windows Phone app to take timed pictures from camera, and upload them on an Apache webserver to view them remotely

Latest Articles

by Peter Huber SG
How to correct the problem that the DispatcherTimer raises the Tick events slower than required by Interval
by Rick York
A simple, header-only class for high resolution timing
by Mehedi Shams
Word-making game!
by Tony Zackin
A very simple yet customizable pop-up message box which auto-closes after a specified number of milliseconds.

All Articles

Sort by Score

Timer 

3 Feb 2022 by Peter Huber SG
How to correct the problem that the DispatcherTimer raises the Tick events slower than required by Interval
6 May 2014 by Sergey Alexandrovich Kryukov
Long running tasks are done using threads, not timers. The only one little problem with having some extra thread performing such a long running task under the UI is that you cannot directly operate UI from that thread. This problem is solved using UI thread invocation mechanism.You cannot...
29 Sep 2015 by Leo Chapiro
Try this:using System;using System.Threading;public static class Program{ public static void Main() { // Create a Timer object that knows to call our DisplayTimeEvent // method once every 100 milliseconds. Timer t = new Timer(DisplayTimeEvent,...
19 Dec 2019 by Rick York
A simple, header-only class for high resolution timing
22 Feb 2014 by Sergey Alexandrovich Kryukov
Dave Kreskowiak is right, please see his comment to the question. Nothing is cancelled or disabled.Not only handling Paint event of the PictureBox makes no sense, using PictureBox for rendering graphics makes no sense at all (even though it is possible). This is just a control designed to...
3 May 2014 by OriginalGriff
You can use more than one timer in an app , but it's not a good idea, as timers are scarce resources and you shouldn't use more than you have to. I generally use just one (when I have to) and set it to 1/10th second or similar then use counters within the timer Tick event handler to process...
3 Oct 2016 by lukeer
As OriginalGriff wrote, the System.Windows.Forms.Timer is a UI component. Usually you get it int your application by dragging one onto a Form.But you can instatiate it in code like you would do with every ordinary class. From any thread you like. You can then call it from that thread.But...
17 Jan 2022 by Dave Kreskowiak
That code won't even compile so everything else you said about it doing something doesn't matter. This comparison is not possible and will keep your code from compiling: If Label10.Text >= "1"
13 Feb 2014 by OriginalGriff
Ok, a couple of things.First off, don't use the primary screen width - you can't show your PictureBox outside your Form, so use the form width instead.Secondly, don't look for an exact match - check for "greater than or equal to" instead. Your way works fine when you increment by one, but if...
8 Apr 2014 by Er. Puneet Goel
Its working fine. Try to copy paste this in separate page; ...
24 Apr 2014 by Alan N
You are using one location, the static field t, to store two timer instances. The timer accessible via t is the last one assigned, "Varinder". Although the code is awful, it is possible to make it work as intended, like this :public static void G_TIMER_ELAPSED(object sender, ElapsedEventArgs...
29 Sep 2014 by Sergey Alexandrovich Kryukov
André Name wrote:Ok, it's a Windows Form. I'm like new in C# but I know a bit about it already, I don't say that I am a pro in it now, but I know how some things to get to work already. You also started with no knowledge with C#, so me too now, that's why I can't know everything about it. But...
14 Aug 2015 by Emiliano Musso
How to create a Windows Phone app to take timed pictures from camera, and upload them on an Apache webserver to view them remotely
23 Aug 2016 by F-ES Sitecore
asp.net is a request\response technology....your code runs in response to a request. What can you do if there is no request? Nothing, your code can't run. This is the problem with scheduled tasks in asp.net, there is no guarantee they will run. You can use something like quartz.net which...
23 Sep 2016 by Mehdi Gholam
Don't call Timer.Dispose() on form close, just disable the timer, .net will dispose of the timer with the form when done.
3 Oct 2016 by OriginalGriff
Simple: it's a Control, which means it's a UI component (even if it isn't visible) and they can only ever be accessed on the UI thread. You could - in theory - Invoke it to start it (since Invoke moves the code to the UI thread) but that would probably defeat the purpose of the BackgroundWorker!
9 Jul 2019 by MadMyche
Well, you are missing quite a bit of code; and you really haven't said what your problem is so it makes it kind of hard for anyone to help you out- with the exception of those who have ESP and can read your mind. And do you really want a timer, which is used to raise events after a specified...
2 May 2020 by Richard MacCutchan
Tank capacity 10,000 m3 Flowrate 1000 m3/hour At a guess that is 10 hours The actual calculation being capacity / flowrate.
6 Jul 2020 by Dave Kreskowiak
The easiest way to do this would be to move your long running code to a Task. A CancelationTokenSource already has an implementation for CancelAfter(milliseconds), so this is pretty easy to do. Cancel Async Tasks after a Period of Time (C#) |...
19 Sep 2020 by Richard MacCutchan
The only thing I can see that may be an issue is the following: FillRgn(hdc, hrgnClip, CreateSolidBrush(color)); DeleteObject(SelectObject(hdc, GetStockObject(WHITE_BRUSH))); Are you certain that DeleteObject is actually deleting the solid brush?
13 Jul 2023 by Richard MacCutchan
The main problem that I can see is that you call the ioOperations which will return as soon as the WriteFile has started, since WriteFile returns false for overlapped IO. Returning the value of GetLastError from that call is pointless as your...
9 Feb 2014 by OriginalGriff
Try:Public NoDataAtPort As System.Timers.Timer = New System.Timers.Timer(100)
24 Apr 2014 by Tadit Dash (ତଡିତ୍ କୁମାର ଦାଶ)
The most convenient way to tackle this problem is to implement jQuery Dialog[^].
10 Jun 2014 by Dave Kreskowiak
No, not really. IIS has a habit of stopping your application if it hasn't been active in quite a while.Do to the time frame involved, this would be much better setup as a Scheduled Task of a separate executable.
12 Jun 2014 by CPallini
See, for instance: "Generating gradients programmatically?" at Stack Overflow[^].
1 Jul 2014 by johannesnestler
You answered it for yourself - don't use static variables where instance variables are needed -
4 Jul 2014 by OriginalGriff
Try: Obj.id=1; Obj.name="AA"; TimerObj.Interval = 1000; TimerObj.Tag = Obj; Obj.TimerObj.Tick += new EventHandler(Timer_Tick); ...private void Timer_Tick(object sender, EventArgs e) { Timer t = sender as Timer; if (t != null) { ...
28 Aug 2014 by PIEBALDconsult
I agree with using a Thread rather than a Timer. Unlike Sleep, Join "Blocks the calling thread until a thread terminates, while continuing to perform standard COM and SendMessage pumping."http://msdn.microsoft.com/en-us/library/95hbf2ta(v=vs.110).aspx[^]So here's a simple little...
16 Nov 2014 by Sergey Alexandrovich Kryukov
You did not show where the exception with the message "Object reference not set to an instance of an object" is thrown. Not to worry. This is one of the very easiest cases to detect and fix. It simply means that some member/variable of some reference type is dereferenced by using and of its...
10 Dec 2014 by Maciej Los
Have you searched CodeProject Knowledge Base?See: WPF Sliding Controls Collection – Part 1: Sliding Image Control[^]Making an Image SlideShow in WPF: Part IV[^]
31 Mar 2015 by deepankarbhatnagar
Please have a look on these links, hope these will help to solve your query :Thanks in advance.http://www.c-sharpcorner.com/Forums/Thread/161600/timer-control-with-gridview.aspx[^]How to refresh an ASP.NET GridView...
9 May 2015 by Dave Kreskowiak
You don't get to tell it which thread to use. The Timer doesn't even know which thread it's doing use! From the documentation:System.Threading.Timer, which executes a single callback method on a thread pool thread at regular intervals.You cannot force a thread to execute code whenever...
10 May 2015 by OriginalGriff
You can't, or at least you shouldn't be able to - as the events list are in a private member. But you can for debug purposes: http://stackoverflow.com/questions/660480/determine-list-of-event-handlers-bound-to-event[^]I would not try to use this in production code: the private attribute...
13 Jul 2015 by Wendelius
Inside the timer_Tick method you on each call you loop through the whole lotto array and you set all the objects to green. This is why all of them are changing at the same time.If you want them to change individually, you need to store for example a counter value outside the method and check...
21 Jul 2015 by Richard MacCutchan
Try the following changes, they worked for me: long offset = 0; start.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { focus.setBase(SystemClock.elapsedRealtime() - offset); ...
30 Aug 2015 by chainerlt
private Thread _loggerThread;private readonly object _lockLoggerThread = new object();private void StartLogging(){ StopLogging(); var thread = new Thread(() => { try { var end = DateTime.Now.AddHours(8); while (DateTime.Now
28 Sep 2015 by Andy Lanng
Ok - Here you have a Main thread that starts when the app starts. The Main thread will continue until it reaches an exit condition (usually the end of the code).Any other thread running will be aborted when the Main thread completes.You are starting your timer thread mere moments before...
22 Dec 2015 by CHill60
Firstly - anything that is intended for logging keys, grabbing passwords, hiding from Antivirus is intended for malicious purposes. That behaviour isn't just prohibited here but on all reputable sites. You will get no help with it.Secondly - you said that your teacher asked you to make a...
22 Jun 2016 by CHill60
Use DispatchTimer in WPF - reference tutorial[^] here
23 Aug 2016 by ZurdoDev
You have already asked this question several times and the answer is still the same. Do not use ASP.Net for this. ASP.Net is not designed to be run on schedules. As you know, the code in ASP.Net only runs when someone hits the page and then it stops. That is how it works.You could,...
16 Apr 2017 by Dave Kreskowiak
CheckForIllegalCrossThreadCalls = False Remove that line of code and forget it even exists. You're setting yourself up for bugs that are very difficult to replicate and fix. The timer doesn't stop. It's still running. The problem is your code has the thread that the timer event is firing on...
14 May 2017 by Bryian Tan
You didn't indicate what not working in the post. Look like the Page_PreRender did not get trigger. Couple of thing you do. I think #1 should do the trick based on your scenario. 1. Change the AutoEventWireup="false" to AutoEventWireup="true" 2. Leave the AutoEventWireup="false" and change the...
16 Jun 2017 by OriginalGriff
Stop converting to strings, and convert to DateTime instead: If your value in the DatagridView is a DateTime, then use it directly: DateTime i = (DateTime) datagridview.currentrow.cell[4].value; If it's a string, then Parse it: DateTime i; if...
4 Jul 2017 by Dave Kreskowiak
It doesn't work because the Elapsed event is raised on a different thread[^] from the UI thread (startup). You cannot touch UI controls from anything other than the UI thread. In this case, you're going to have to Invoke a method on the UI thread to change the text in the TextBox. Private...
25 Aug 2017 by OriginalGriff
Instead of creating new timers each time - which is a bad idea, they are a scarce resource in Windows - set up a DateTime collection of end times and use a single running timer to check each of them against DateTime.Now When you find an elapsed period, remove it from the collection and do your...
11 Dec 2017 by Leo Chapiro
Do it step by step: first look how the timer works. Forget about writing to excel, that is another task that is not depending on timer's task for now. So you would now initialize your timer, start it by click-on the check box and stop it by click-off the check box and write the current time on...
11 Mar 2018 by RickZeeland
The easiest option is to use a System.Windows.Forms.Timer see example here: Timer Class (System.Windows.Forms)[^] You can define the Timer in code, or drag one from the Toolbox onto your form. More information on Timers here: Timers[^]
27 Mar 2019 by OriginalGriff
Set the timer Interval to 10 seconds: 10000 Handle the Timer Tick event Start the timer. In the tick handler, call your method.
10 Jul 2019 by CPallini
This happens because totaltime.Text it is not a compliant string representation of an integer. You might either Handle the excetpion (see the the code sample in the documentation[^]). or Use, as already suggested, the Int32.TryParse[^] method.
11 Oct 2019 by F-ES Sitecore
Try setting the updatemode of the updatepanels to Conditional UpdatePanel.UpdateMode Property (System.Web.UI) | Microsoft Docs[^] That should mean each panel only updates when something in it triggers the update, it won't update when other panels update. Note that the code-behind lifecycle...
11 Feb 2020 by OriginalGriff
Variables aren't the same thing as the instance they contain: just setting a variable to null doesn't change the object it used to "point to", and it doesn't in any way mean that the system will immediately destroy (or even begin the process of...
4 Mar 2020 by OriginalGriff
You need to learn how things work: when you refresh a page, your request a new copy of it from the server, and that discards everything that has been done to the page so far - and that includes timers. You can't start a timer that works even when...
6 Jul 2020 by Garth J Lancaster
Following from Dave's suggestion, I 'think' (*tm, I'm not a VB.Net Programmer) you could do something like ' Declare a System.Threading.CancellationTokenSource. Dim cts As CancellationTokenSource Private Async Sub unreliableLongProcess() as...
24 Jul 2020 by Richard MacCutchan
Quote: cant find the timer tick code Does it occur to you that maybe you should write it yourself? The Timer control inVB.NET can be found in the toolbox, so you can add that to your form quite easily. Once you have that then you can read the...
19 Sep 2020 by Patrice T
your code is very simple minded, and it is bad. Quote: i use Timer which redraws the digits every 100 milliseconds. A simple test can divide by 10 the workload of redraw: if (LastTime != NewTime) { redrawClock(); LastTime = NewTime; } ...
21 Nov 2020 by Dave Kreskowiak
That's not going to happen on Windows. You cannot get that kind of precision on a shared system that is not a real-time O/S. Events like that are guaranteed to happen NO SOONER THAN SCHEDULED. That does not mean exactly as scheduled.
8 Sep 2022 by OriginalGriff
This bit: System.Windows.Forms.Timer timer1 = new System.Windows.Forms.Timer(); timer1.Interval=300000;//5 minutes timer1.Tick += new System.EventHandler(timer1_Tick); timer1.Start(); Needs to be inside a method, probably the Form.Shown event...
15 Sep 2023 by Richard MacCutchan
Try this: #include #include DWORD waitThread(HANDLE hThread) { DWORD dwTimeOut{ 10000 }; const char* emsg{}; switch (WaitForSingleObject(hThread, dwTimeOut)) { case WAIT_OBJECT_0: return...
16 Jan 2014 by Sriram Ramachandran
A quick question .... I need to write services in C#. The service should have specific timer which should check in DB and retrieves the date. For example... In application, the user gives "Remind me after 2 days" In background, after 2 days, I should load the data where the user marked...
16 Jan 2014 by Deviprasad Das
Step 1: From the web app you need to store the user selected value in DB (2 days).Step 2: You can create a Windows Service, which will keep on checking the DB, and fires a particular event (when that particular date comes), and may do an insert or update.
4 Feb 2014 by Sergey Alexandrovich Kryukov
It depends on what do you want to get: a point in time, or a time span between some point. Apparently those are conceptually different and are represented by different...
9 Feb 2014 by glennPattonWork3
I am battling with VB again I have used a timer in C# as followsNoDataAtPort = new System.Timers.Timer(100); NoDataAtPort.Elapsed += new ElapsedEventHandler(OnTimeOut)In VB this is :Public NoDataAtPort = New System.Timers.Timer(100)Public NoDataAtPort.Elapsed += New...
16 Feb 2014 by nvnq
I have the table like that,Index | Time | Tem | Hum | Rain | Wind | Level 1 2Here's the code:public class MyTable1 extends JFrame { MyTable1 mytable; Object[][] data; JTable tb; JScrollPane scp; int MAXH=100,MAXC=100; public...
10 Mar 2014 by BillWoodruff
The variation in timing may be due to garbage collection happening; read the commented code in the 'Main method here: [^]. Use of the 'GC.KeepAlive(YourTimerName) may have an impact on this variation.In any case you can simplify your code by setting the 'Synchronization object-property of...
23 Mar 2014 by luis armando Molina
I have a grid that I want to bind every X seconds, but the timer is not waiting until the process is done, it's just executing itself over and over, I even tried creating a variable, and use it as a flag, but it doesn't seem to be working, here is my code(the problem is not in my code behind, if...
23 Mar 2014 by Krishna Madhav Majety
Can you check a flag in your Timer1_Tick() -> If true GetLatestDataForGrid() -> Else ignore -> Set flag=FalseAnd set that flag to TRUE after completion of your gridLoad.
24 Apr 2014 by Rahul VB
Hello Friends, Hello Friends, I am working on a timer based project. I need that the timer should elapse just once. I wrote the following code: class Program { static void Main(string[] args) { Start_Event_Timer("Rahul"); ...
24 Apr 2014 by Xiao Ling
Only the pages hosted by yourself can be opened automatically. If you want to open other sites automatically, you need to set them trusted. The security mechanism is not only implemented in FireFox, but also Chrome and IE.
6 May 2014 by MNamrata
Use update panel around button and give asyncronouspostback trigger for that button
6 May 2014 by Prasad Avunoori
Hi Harnis,1.When the user clicks on "Start Exam" button enter target time in the database.e.g. "2014-05-06 18:00:00.000"2.Bind that datetime to a Label3.Now generate the countdown timer from that DateTime(Label Text).4.Count down timer wouldn't be changed even if the user...
25 May 2014 by Tracy Chong
Hello, I need some help.Currently, I have a gridview that will update with the timer and also a button when clicked, will update the gridview.So now, I am currently facing a problem regarding when scrolling the updatepanel/gridview, I would like it to remain at scrollbar position. But...
25 May 2014 by Debabrata_Das
Just wondering if you have already tried by adding MaintainScrollPositionOnPostback="true" in Page tag.
29 May 2014 by Peter Leow
Ask Google[^]
30 May 2014 by Manikandan10
Use QTimer:http://developer.nokia.com/community/wiki/How_to_use_QTimer_in_Qt[^]
3 Jun 2014 by mary99
I want to create a timer in QT that shows minutes, seconds and hundreds of a second. I want to show digits in a QPlaniTextEdit. When I push the start_button, there must be timer showed in QPlaintextedit. I wrote this code but I don't know how to show the time and what to write in slot. My timer...
10 Jun 2014 by adriancs
I'm using System.Timers to schedule tasks. I find this working, but I'm not quite sure if it's ok to do it this way.using System.Web;using System.Web.Security;using System.Web.SessionState;using System.Timers;using System.IO;using System.Threading;namespace WebApplication1{...
12 Jun 2014 by Member 3293815
Hi all,after trying a lot of coding around and searching in the web, I am hoping to find an answer here.My C#/WPF application needs the user to draw lines continuously in different directions, such that each line is connected to the previous one. Now, I have implemented a timer to change...
15 Jun 2014 by V.
I would keep the word in an array which contains an object. That object contains one letter and one boolean. Each time you enter a letter you run through the array and set the booleans to true if it encounters the correct letter. If at the end nothing was set to true you add a piece of the...
30 Jun 2014 by packodilal
i have to develop multi user online exam system all work is completed but one problem is thatwhen another user login in exam system then his timer value change the previous user Timer value.i have use 2 static int value for minute and second.Please help my code isstatic int...
30 Jun 2014 by DamithSL
when user logged in you can reset the values as below protected void SetExamTimer() { tmpStartmin=0; tmpStartSecond = 59;or use another two session values for start minutes and start seconds. clear those session values on user log out and log in.
4 Jul 2014 by ABBASI_RA
dear friendsi have a class likeclass1{int id;string name;public System.Windows.Forms.Timer TimerObj = new System.Windows.Forms.Timer();}then create objectclass1 Obj = new class1();Obj.id=1;Obj.name="AA";TimerObj.Interval = 1000;Obj.TimerObj.Tick += new...
13 Jul 2014 by Tino Fourie
Not sure if the OP is still in need of a solution judging from what replies he got - nothing of value - and the date this question was posted.I have a similar situation while sending an email with attachments. I use a single Timer control to manage the "firing" order of my Backgroundworker...
15 Jul 2014 by Yannick Brodard
How do I add a timer and it's events in my WCF Application Service ? My WCF receives files from a client and I save them in a SQL Server Database.I would like to send the received files to an other service that I do not control. But I don't want to make the client wait for a return of the...
15 Jul 2014 by Yannick Brodard
Thanks to the comments, I found out that I didn't need a timer but instead an async on the SendToOtherService(dbFile), so SendToOtherService became SendToOtherServiceAsync. Thank you very much for your comments.public async void SendToOtherServiceAsync(FileModel dbFile){ //...
12 Sep 2014 by Member 11067180
Language UKEnvironment ?Why - To show customers how long they have to order before receiving goods next day :)
30 Sep 2014 by Kinna-10626331
I am a beginner with C# and WPF.I would like to read from a CSV . I would like to pick up a line from the CSV each 30 second and with the fields of the line update the values in a User control ( a gauge with a Text box).What I have already: I am doing something similar with a button event. I...
30 Sep 2014 by Kinna-10626331
I solve it , I apply the timer into the user control and elapse the interval with a read event: public Wind_gauge() { InitializeComponent(); this.Loaded += new RoutedEventHandler(Window1_Loaded);//launched event timer = new Timer(3000); ...
26 Oct 2014 by Atinesh
In my building an Auction website which has an area, Where I need to implement a global timer (say for 10secs) for each products which are available for live biding. Whenever a user clicks the button "Submit" the timer must get reset and whenever the timer get expired then the last user that has...
14 Nov 2014 by Nitin Guralwar
using System;using System.Collections.Generic;using System.Linq;using System.Web.UI;using System.Web.UI.WebControls;using System.Collections;using System.ComponentModel;using System.Data;using System.Drawing;using System.Web;using System.Web.SessionState;using...
15 Nov 2014 by Nitin Guralwar
15 Nov 2014 by DamithSL
in your aspx page code file is CodeBehind="L_PaperSet.aspx.cs" but you may have renamed it to something else. give the correct name of WebForm2 class cs file, then this error will be vanished.
15 Nov 2014 by George Jonsson
Have you tried to make the method public?protected void Timer1_Tick(object sender, EventArgs e)public void Timer1_Tick(object sender, EventArgs e){ NewMethod();}
16 Nov 2014 by Hassan(Aych Jay)
The application is running absolutely fine however when i lock my PC and the timer ticks (the tick is set at 60 seconds) then this error is seen. After this the application does not work even if i click continue.************** Exception Text **************System.NullReferenceException:...
24 Dec 2014 by Nishant Bhuskade
I am inserting data in one table(e.g. InsertTable) & updating another table(e.g. UpldTable) in a loop on a button click.(say loop of 2500 iterations)I want to retrieve updated value from UpldTable. & display it on same page.And on timer_tick event i display value from UpldTable after every 2...
2 Feb 2015 by Stan Huang
I created a timer using VC# which working seems fine. The problem is that I must show message at the time when timer event handler is called. I found the MessageBox.Show not working. Below is my modified code snippet, in which I simplified the event handler as just showing a message.My window...
2 Feb 2015 by _Asif_
Check below link, this will not only give you detail info about problem but also suggest solutions as well (The link though discuss console application but you may do the same in your application as well)Message box in front of all windows in console application?[^]
4 Feb 2015 by Stan Huang
Refer here:TopMost MessageBox[^]It works; but I still wonder the simpler solotion. In my opinion, showing message at top of all windows or at least the current window must be very popular option in Windows programming. How come it needs so lots of codes to do it? It should need only one...
2 Mar 2015 by Kinna-10626331
Hello , basically I want to refresh the x axe with new values coming.Chart.xaml:
21 Mar 2015 by Member 11410952
using System;using System.Timers;public partial class copy_option : System.Web.UI.Page{ private System.Timers.Timer aTimer; protected void Page_Load(object sender, EventArgs e) { // Create a timer with a two second interval. aTimer = new...