4 Replies - 588 Views - Last Post: 29 April 2015 - 10:17 AM Rate Topic: -----

#1 adolf625  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 22
  • View blog
  • Posts: 172
  • Joined: 22-November 08

Question about Timers

Posted 29 April 2015 - 07:58 AM

Ok, I have a simple question about timers in a Windows Form application. I have two timers attached to a form. One to listen for an alarm message and another to listen for an alarm acknowledgement. The alarm timer will check the database every 2 seconds to see if an alarm has been triggered. Once there is an alarm record found, it will stop this timer, start the timer to listen for the acknowledgment, hide the form that the timers are attached to and display another form that describes the actual alarm. The question I have is will hiding a form disable the timer or will the timer still be active even though the form is hidden?

Is This A Good Question/Topic? 0
  • +

Replies To: Question about Timers

#2 Michael26  Icon User is offline

  • Futurama: Insert funny joke here
  • member icon

Reputation: 414
  • View blog
  • Posts: 1,664
  • Joined: 08-April 09

Re: Question about Timers

Posted 29 April 2015 - 08:05 AM

Quote

The question I have is will hiding a form disable the timer or will the timer still be active even though the form is hidden?


Have you tried to do that?
Do you know how debugging works?
Was This Post Helpful? 0
  • +
  • -

#3 adolf625  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 22
  • View blog
  • Posts: 172
  • Joined: 22-November 08

Re: Question about Timers

Posted 29 April 2015 - 08:10 AM

I am in a situation what I cannot test everything until a week out, I am just trying to get the application as close to complete as I can before then, and I wasn't certain about the timers.
Was This Post Helpful? 0
  • +
  • -

#4 tlhIn`toq  Icon User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6507
  • View blog
  • Posts: 14,377
  • Joined: 02-June 10

Re: Question about Timers

Posted 29 April 2015 - 10:06 AM

Code will run even when the form is hidden.

My concerns are about your design:
  • Why a legacy WinForms app any time after the year 2001?
  • Why a timer? Instead of hammering the database with reads to see if there is a change (and in an effort to give the hard drive an early death) wouldn't it be better to program an Event Notification in the the database? Then you'd have a service in your application that receives the notice. Under that model you react to an event just like any other program event, instead of the huge waste of CPU cycles. This looked to be a decent tutorial using a chat program as an example. When one chatter creates a message it goes to the database, that triggers an event notification and the other chatter 'hears' that there was an update to the database and reacts to the event.
    http://www.codeproje...a-change-events

This post has been edited by tlhIn`toq: 29 April 2015 - 10:06 AM

Was This Post Helpful? 0
  • +
  • -

#5 Curtis Rutland  Icon User is offline

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 5101
  • View blog
  • Posts: 9,283
  • Joined: 08-June 10

Re: Question about Timers

Posted 29 April 2015 - 10:17 AM

Right, but there's a skill to be learned here: creating specific tests. Personally, I do know how that will behave: System.Windows.Forms.Timer will continue to tick even if the form is not visible. But if I didn't, here's how I would figure it out:

I'd start a New Project. Then I'd add a timer with a short interval, a button to hide the form, and a multiline text box to put a timestamp in each time the timer ticks. Start the form, start the timer, hide the form, wait, unhide the form, see if it has written to the textbox while it's hidden.

That's one of the best ways to learn about code components: make a proof-of-concept, reduced down to literally just the question you want answered. You'll end up with dozens of test projects this way, so I suggest making one solution, and adding a new project for each kind of thing you want to test, then cleaning up later to test new things. For instance, I have a solution with a Console, WinForm, WPF, and ASP.NET MVC project. I go in and set one to a startup project, clear it out, and put in whatever new I want to test out.

That's one of the reasons I never ask questions on these forums; I investigate until I figure it out.

Side note: LINQPad is an awesome tool for this. You don't need a project or a solution, and LINQPad is smart enough to be able to dump out arbitrary objects.
Was This Post Helpful? 3
  • +
  • -

Page 1 of 1