|
|
Ok, If I have learned correctly, one should limit an app to maybe 1 or 2 timers.
I have a timer object set to triger every second, but I need a number of different events to happen at different times.
For example,
every 1 second...timer triggers
every 3 seconds, run function A
every 10 seconds, run function B
etc
Now, I cant figure out how to do this properly. I know I need variables to keep tabs on elapsed times, but would some kind coder please give me an example of how I may do this please?
Thank you
Steve
|
|
|
|
|
Hi,
1.
you can have several timers, however I would avoid having dozens of them.
2.
you can easily combine two or more periodic timer requirements and serve them by a single timer, basically it works like this (code looks like C#, has not been tested):
public class MultiTimerDemo {
private int timerCounter17=0;
private int timerCounter5=0;
public MultiTimerDemo() {
Windows.Forms.Timer timer=new Windows.Forms.Timer();
timer.Interval=1000;
timer.Tick+=ticker;
timer.Start();
}
private void ticker(object sender, EventArgs e) {
if (--timerCounter5<=0) {
timerCounter5=5;
.. now do whatever needs to be done every 5 seconds
}
if (--timerCounter17<=0) {
timerCounter17=17;
.. now do whatever needs to be done every 17 seconds
}
}
}
The above illustrates how one actual timer can be turned into two or more virtual timers.
You can easily add virtual timers. And of course you could make things more dynamic (provide code to add and remove all kinds of virtual timers) by using lists and delegates.
|
|
|
|
|
Thanx alot Luc, just what I needed!
Steve
|
|
|
|
|
One timer. One second interval. Keep a DateTime of when each task last ran. When the timer elapses, iterate the tasks to see which are due.
That's basically what I do, but with the tasks configured in a database.
|
|
|
|
|
Hi again coders.
I am writing my first, simple patient simulator.
I need to play a sound file on repeat, while the simulator is running.
It is a beep beep kind of file for the ECG machine (EKG in america, I am in UK)
I have a time object in my c# app, set to triger every second so I can track each second of the currently running simulation.
I tried to add my playsound() function here, but it is being reset every second (I understand why, but I cannot figure out what to do)
The whole sound file lasts approx 12 seconds, and needs to repeat straignt after it ends, for as long as the sim is running)
Sorry if it a basic question, but what functions do I need, and where would I put them to allow me to do this?
Thank you
Steve
|
|
|
|
|
stephen.darling wrote: I have a time object in my c# app, set to triger every second
Perhaps you could have this trigger every 12 seconds? Or if it needs to be every second, have a variable track how many times it has triggered and every 12 times, you can play the sound (the other 11 times you'd skip the sound playing since it's already playing and you'd do whatever you do on that trigger).
stephen.darling wrote: I tried to add my playsound() function here
Speaking of adding your playsound function here, you should post some code here so we know the actual functions you are using to play the sound and which objects you are using for your timer.
|
|
|
|
|
Hello and thank you.
Here is my code, but it is rough as i have not yet created the classes etc, it is all happening within the form function
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Threading;
using System.IO;
using System.Text;
using System.Runtime.InteropServices;
namespace SimMed
{
public partial class simmedForm : Form
{
[DllImport("winmm.dll")]
private static extern bool PlaySound(string lpszName, int hModule, int dwFlags);
#region Variables
private int nTime;
private int patientHeartRate;
private int patientBloodPressure;
private int patientTemp;
private int patientBreathRate;
private int patientConciousLevel;
#endregion
public simmedForm()
{
InitializeComponent();
HeartBpmLed.Text = ("72");
patientHeartRate = 72;
startNewSimulation(false);
}
private void startNewSimulation(bool restart)
{
if (timer1.Enabled) timer1.Stop();
if (!timer1.Enabled) InitTimer();
}
private void InitTimer()
{
timer1.Interval = 1000;
timer1.Enabled = true;
}
private void PlayWav(int play)
{
string myFile = ".\\Sounds\\default.wav";
switch (play)
{
case 1:
myFile = ".\\Sounds\\ecg.wav";
break;
case 2:
myFile = ".\\Sounds\\ecg.wav";
break;
case 3:
myFile = ".\\Sounds\\ecg.wav";
break;
case 4:
myFile = ".\\Sounds\\ECG Alarm.wav";
break;
case 5:
myFile = ".\\Sounds\\Flatline.wav";
break;
case 6:
myFile = ".\\Sounds\\Medicalventilator.wav";
break;
case 7:
myFile = ".\\Sounds\\PulseOximeter.wav";
break;
case 8:
myFile = ".\\Sounds\\Heartbeat.wav";
break;
case 9:
myFile = ".\\Sounds\\Won.wav";
break;
case 10:
myFile = ".\\Sounds\\illegal.wav";
break;
default:
break;
}
PlaySound(myFile, 0, 0x0003);
}
private void simmedForm_Load(object sender, EventArgs e)
{
}
private void timer1_Tick(object sender, EventArgs e)
{
Random r1 = new Random(unchecked((int)DateTime.Now.Ticks));
nTime++;
patientHeartRate = 72 + r1.Next(0, 5);
HeartBpmLed.Text = patientHeartRate.ToString();
PlayWav(1);
}
}
}
Thank you
|
|
|
|
|
|
Ah, OK.
I will look into this function.
Thank you
|
|
|
|
|
|
Thank you for that really useful information <Sarcasm mode="off" />
Did you mean to post it somewhere else, or are you just not big on reading?
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
So write an article then.
|
|
|
|
|
How does it differ from storing my stored procedures as plain text files and pulling them from harddisk as needed?
I are Troll
|
|
|
|
|
How are you able to control objects in your project with stored procedures? Not objects in database.
Without hard-coding it into your code.
|
|
|
|
|
hove82 wrote: Not objects in database.
Without hard-coding it into your code.
You're sounding like a salesman. Don't do that if you want a decent opinion.
I put objects in my database by serializing them. I put assemblies in my database as blobs, based on the source-code that's stored in a NVARCHAR. Updating the text in the NVARCHAR gives a new build-number, and there's a certain amount of builds in a release
What's the motivation behind the original question? Do you plan on using their software and looking for people with previous experience, are you evaluating idea's, or what? Without a decent list of features, it's hard to say whether or not it would fit a specific task.
Yes, it's definitely handy for those people who don't want to spend the time on building that part of the infrastructure themselves. There's room for logging-frameworks, for exception-handling frameworks, should be room for a macro/configurationmanager framework.
Is it Open Source? If yes, then why not write an article on it's use, and how it could save people time?
I are Troll
|
|
|
|
|
Now I want to know what he was talking about...
|
|
|
|
|
I am not a salesman.
I has been moved to an article ObjectPolicy.
This project is about not including certain things into project (hard-coding), but to be able to control it from a volatile source.
modified on Tuesday, September 14, 2010 2:04 AM
|
|
|
|
|
hove82 wrote: I am not a salesman.
I has been moved to an article ObjectPolicy.
My apologies, but for a split second you sounded like one. Looking back, it sounds logical that you'd be excited and enthusiastic. Good to hear that there's an article upcoming
hove82 wrote: This project is about not including certain things into project (hard-coding), but to be able to control it from a volatile source.
That's a portable, cross-platform source? You mentioned XML as a source, which could mean that it might run on Mono without any modifications. Might even work from a memory-stick.
Some people will be interested in the product, others more in how you created it, but most in both
I are Troll
|
|
|
|
|
Just to be clear, ObjectPolicy reads, interprets and executes commands written in xml, it's not standalone solution, you need to implement it in your application. It's all about mapping objects in xml with objects in your application, and issuing command against them, that's what ObjectPolicy does.
My article was deleted because I refuse to post a source code. You can download dll, or test app from here.
|
|
|
|
|
hove82 wrote: Just to be clear, ObjectPolicy reads, interprets and executes commands written in xml
It's not clear; I had to look at the XML to see what you actually meant by that.
hove82 wrote: You can downloaded it from here.
Thanks for the link, downloaded it. Looks like 's easy to use, and has a small footprint. Looks portable.
I'm not running Windows, and Linux doesn't like the precompiled version since that targets .NET 4.0. Do you need the stuff from the 4.0 framework, or does it also build under 2.0?
hove82 wrote: My article was deleted because I refuse to post a source code.
Posting an article to promote closed-source ("commercial") software would be seen as an attempt to post an advertisement without paying. If the software was open-source then you could reach a nice audience here.
Yes, there's quite some criticism at the start, and it's impossible to please everyone. And yes, I'm interested, but as a programmer - not as a customer.
I are Troll
|
|
|
|
|
I am using some things from .net 4.0, but I think it won't be too much of a trouble to make it work in 2.0.
|
|
|
|
|
hove82 wrote: What are your opinions about this project? Is it useful? Is it a good idea?
Seriously - write an article on it. You've posted this in a forum that's aimed at people asking questions, completely missing the whole article sections.
|
|
|
|
|
|
Hi guys
I have a form that has like 30 controls on them all of them have data that it loads to from a DB, is there a efficient way to only get the data or control that was modified?
Thanks
|
|
|
|
|