473,387 Members | 1,463 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,387 software developers and data experts.

Windows Form application Timer Tick

Hi!

I use C# 4.0 to build a windows form application.
I have a Windows Forms Timer that should tick every second. In every tick I do some work (get GPS position, update a map, save to a local DB etc). It takes about 0.09 sec to execute. The save to the local DB is done async to release the GUI thread faster but the other code is executed on the GUI thread (need to for updating the GUI)

Some time the tick is not fired constantly, it can be several seconds between (I guess the GUI thread is busy in some way).

How can I rewrite so that there always will be a tick on time, is it possible? The program runs on machine with a single processor. Most of the time the CPU usage is not very high.

Would there be any meaning to switch to a System.Threading Timer to get more accuracy? I do need to be on the GUI thread most of the time during the Timer execution.

Regards
Henrik
Feb 21 '11 #1
5 4096
GaryTexmo
1,501 Expert 1GB
I'd recommend looking into threading or a background worker for this. When your timer ticks, create a thread to handle your update. You can have attach an event to when it's finished so that your GUI can do anything else it needs to when that's finished.

I notice you said you are doing this asynchronously so perhaps you already know about this. I figured I'd mention it anyway :)

What I'm curious about is why your timer doesn't tick on time. You've got it to tick every second and that's plenty of time for you to get your calculations done. So if it's not ticking on time, there's something else going on here. What would be preventing the timing, especially since your work is getting done asynchronously?

Is the GUI update taking longer than your 1 second tick window?
Feb 22 '11 #2
The GUI update should be much faster than 1 second. but since there are other software involved (3:part) updating the GUI, its hard to know how much time and power it takes.

But something is taking time, I have tried to do as much as possible in other threads (async).
Feb 24 '11 #3
GaryTexmo
1,501 Expert 1GB
Have you considered having separate timers for your GUI update and your logic updates?
Feb 24 '11 #4
Yes, I have considered many different solutions. I do think that the GUI update must be tight connected to the other updates for it to be real-time feeling for the user...
Feb 25 '11 #5
GaryTexmo
1,501 Expert 1GB
I don't know that's not always true. Where I'm coming from is a gaming standpoint. Often, a game's update loop happens more often than the display loop. Really, the human eye/brain can only comprehend information so quickly so it makes a bit of sense. The display method doesn't generate/process any new information, it only displays graphically the current state of the information.

I'm just throwing this out there for you to consider. If you can't do this in your program, you can't. At some point though, if your updates/display are taking longer than your time slice you'll either have to expand your time slice or do less work in each time slice. You can accomplish the latter by either reducing the complexity of your code, or performing some tasks in alternating time slices.
Feb 25 '11 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: David | last post by:
So I'm a new user to Visual Studio .NET. I'm having a problem with an initial setup of a Windows Form Application for a Visual C++ Project. The Windows Form Application (.NET) template is not...
0
by: forge | last post by:
Installing Merge Modules from C# Windows Form Application (not using a setup and deployment project) Hi, Currently, we have an InstallShield project that creates a setup.exe that only...
1
by: Dean R. Henderson | last post by:
I have a Windows library that I bind into a Windows Form application and into an ASP.NET Web Application. I have a procedure in the library that executes a DTS Package. I have also used...
4
by: bob lambert | last post by:
Help I am trying to deploy to another pc a vb.net std 2002 windows form application. I am confused. I created a project - windows form I built form, compiled and debugged. I created a...
3
by: Henry Seymour | last post by:
I've developed a .Net Windows Form application and used the Click-Once Deployment. In that application I would like to allow the user a click-once method of uninstalling it. I do not find an...
1
by: Dave | last post by:
Hello all, I have an application that is accessing files from a mapped drive. I have full access to the share that is mapped and from explorer can delete files as I need. My application needs to...
0
by: querry | last post by:
Hi all, I am developing a Windows form Application in VC++.NET using the Visual Studio 2005 installed on Windows Server 2003. The UI part of the project is almost complete. I am now looking forward...
2
by: ashkan0021 | last post by:
hi, i have a solution in C#.Net that includes 2 project and ASP.net & A Windows form application project, i want to open some pages of my asp.net project in my windows application, i'd be realy...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...

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.