473,473 Members | 1,739 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Creating Events

Hi,
I have a timer class and I would like to send an event based on specifc
times from the timer,
example at maybe every 500ms call a function, most likely a callback,
similar to the way the Systems.Timer works.
Is there a way one can create events to accomplish this?
Thanks
Jeff

Sep 7 '06 #1
11 1953
There is already a timer class to do this. Is there any reason you
wanted to do it, yourself?

--
Sean
Sep 7 '06 #2
Hello Hoop,

Timer class supports System.Threading.TimerCallback callback
see http://msdn.microsoft.com/library/de...sctortopic.asp

HHi,
HI have a timer class and I would like to send an event based on
Hspecifc
Htimes from the timer,
Hexample at maybe every 500ms call a function, most likely a callback,
Hsimilar to the way the Systems.Timer works.
HIs there a way one can create events to accomplish this?
HThanks
HJeff
---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
Sep 7 '06 #3
Hi Sean,
I have the timer class running allready. Resolution is only 55ms at
best.
I need something much faster, so I have HighRes timer class that I
would like somehow to be event driven in the same way as the timer.
Thought may there was a way to add user defined events.
Thanks
Jeff
senfo wrote:
There is already a timer class to do this. Is there any reason you
wanted to do it, yourself?

--
Sean
Sep 7 '06 #4
Hi Michael,
I have tried System.Threading.Timer. Works much better than standard
windows timer. That is most likely what I will
wind up using. Was just trying to see if there was a way that I could
try this HighRes timer class
that I have.
Thanks
Jeff

Michael Nemtsev wrote:
Hello Hoop,

Timer class supports System.Threading.TimerCallback callback
see http://msdn.microsoft.com/library/de...sctortopic.asp

HHi,
HI have a timer class and I would like to send an event based on
Hspecifc
Htimes from the timer,
Hexample at maybe every 500ms call a function, most likely a callback,
Hsimilar to the way the Systems.Timer works.
HIs there a way one can create events to accomplish this?
HThanks
HJeff
---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
Sep 7 '06 #5
Hello Hoop,

How much faster do u need? Windows is not real time OS. AFAIK the bottom
line is 20ms

HHi Michael,
HI have tried System.Threading.Timer. Works much better than standard
Hwindows timer. That is most likely what I will
Hwind up using. Was just trying to see if there was a way that I could
Htry this HighRes timer class
Hthat I have.
HThanks
HJeff
HMichael Nemtsev wrote:
H>
>Hello Hoop,

Timer class supports System.Threading.TimerCallback callback

see
http://msdn.microsoft.com/library/de...ary/en-us/cpre
f/html/frlrfsystemthreadingtimerclassctortopic.asp

HHi,
HI have a timer class and I would like to send an event based on
Hspecifc
Htimes from the timer,
Hexample at maybe every 500ms call a function, most likely a
callback,
Hsimilar to the way the Systems.Timer works.
HIs there a way one can create events to accomplish this?
HThanks
HJeff
---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour
"At times one remains faithful to a cause only because its opponents
do not cease to be insipid." (c) Friedrich Nietzsche
---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
Sep 7 '06 #6
Hi Michael,
Probably using the threading timer is maybe going to be OK, or maybe
just a thread and sleep() it for a some chosen time.
But I was trying to see if QueryPerformanceCounter() could beat it. I
have seen 15ms with the treading timer. A little jumpy but that might
work.
Thanks
Jeff

Michael Nemtsev wrote:
Hello Hoop,

How much faster do u need? Windows is not real time OS. AFAIK the bottom
line is 20ms

HHi Michael,
HI have tried System.Threading.Timer. Works much better than standard
Hwindows timer. That is most likely what I will
Hwind up using. Was just trying to see if there was a way that I could
Htry this HighRes timer class
Hthat I have.
HThanks
HJeff
HMichael Nemtsev wrote:
H>
Hello Hoop,

Timer class supports System.Threading.TimerCallback callback

see
http://msdn.microsoft.com/library/de...ary/en-us/cpre
f/html/frlrfsystemthreadingtimerclassctortopic.asp

HHi,
HI have a timer class and I would like to send an event based on
Hspecifc
Htimes from the timer,
Hexample at maybe every 500ms call a function, most likely a
callback,
Hsimilar to the way the Systems.Timer works.
HIs there a way one can create events to accomplish this?
HThanks
HJeff
---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour
"At times one remains faithful to a cause only because its opponents
do not cease to be insipid." (c) Friedrich Nietzsche
---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
Sep 7 '06 #7
"Hoop" <jc******@oshtruck.comwrote in message
news:11**********************@i3g2000cwc.googlegro ups.com...
Hi Michael,
Probably using the threading timer is maybe going to be OK, or maybe
just a thread and sleep() it for a some chosen time.
But I was trying to see if QueryPerformanceCounter() could beat it. I
have seen 15ms with the treading timer. A little jumpy but that might
work.
Thanks
Jeff
Waitable Timer, WaitForSingle/MultipleObject with a timeout, or select() all
should give better resolution. I have had 60 fps graphing using
MsgWaitForMultipleObjectsEx on a waitable timer in C++, and I think it could
have been smoother yet, but my graph only had room for 60 horizontal
pixels/second.
>
Michael Nemtsev wrote:
>Hello Hoop,

How much faster do u need? Windows is not real time OS. AFAIK the bottom
line is 20ms

HHi Michael,
HI have tried System.Threading.Timer. Works much better than standard
Hwindows timer. That is most likely what I will
Hwind up using. Was just trying to see if there was a way that I could
Htry this HighRes timer class
Hthat I have.
HThanks
HJeff
HMichael Nemtsev wrote:
H>
>Hello Hoop,

Timer class supports System.Threading.TimerCallback callback

see
http://msdn.microsoft.com/library/de...ary/en-us/cpre
f/html/frlrfsystemthreadingtimerclassctortopic.asp

HHi,
HI have a timer class and I would like to send an event based on
Hspecifc
Htimes from the timer,
Hexample at maybe every 500ms call a function, most likely a
callback,
Hsimilar to the way the Systems.Timer works.
HIs there a way one can create events to accomplish this?
HThanks
HJeff
---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour
"At times one remains faithful to a cause only because its opponents
do not cease to be insipid." (c) Friedrich Nietzsche
---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do
not
cease to be insipid." (c) Friedrich Nietzsche

Sep 8 '06 #8
Hi Sean,
Yes, that looks like what I want to try.
I am having trouble with setting up the event to run.

After adding that code to the HiResTimer(),
In my main form, pressureForm, in the constructor, I do

public pressureForm()
{
startTimer()
}

startTimer()
{
MyTimer.HiResTimer.Start();

//Error, the name Expired does not exist in the current context
MyTimer.HiResTimer.ElapasedTime += new EventHandler(Expired);

}

Must not be exact way to do it.
Jeff

Ben Voigt wrote:
"Hoop" <jc******@oshtruck.comwrote in message
news:11*********************@i3g2000cwc.googlegrou ps.com...
Hi Sean,
I have the timer class running allready. Resolution is only 55ms at
best.
I need something much faster, so I have HighRes timer class that I
would like somehow to be event driven in the same way as the timer.
Thought may there was a way to add user defined events.

Absolutely. Add the following inside your class:

public event EventHandler Expired;
private void CallInterestedParties()
{
if (Expired != null) Expired(/* sender */ this, /* EventArgs */
EventArgs.Empty);
}

Thanks
Jeff
senfo wrote:
There is already a timer class to do this. Is there any reason you
wanted to do it, yourself?

--
Sean
Sep 11 '06 #9
Hoop <jc******@oshtruck.comwrote:
Yes, that looks like what I want to try.
I am having trouble with setting up the event to run.

After adding that code to the HiResTimer(),
In my main form, pressureForm, in the constructor, I do

public pressureForm()
{
startTimer()
}

startTimer()
{
MyTimer.HiResTimer.Start();

//Error, the name Expired does not exist in the current context
MyTimer.HiResTimer.ElapasedTime += new EventHandler(Expired);

}

Must not be exact way to do it.
Expired is the name of an event, but you're trying to create an
EventHandler from it as if it were a method. When you subscribe to
ElapsedTime, you'll need to do so with a method. I suggest you write a
method which just calls Expired. You *could* just write:

MyTimer.HiResTimer.ElapasedTime += Expired;

but that will take the current value of the field-like event's delegate
instance instead of really associating the two events.

If all that was gobbledy-gook, read
http://www.pobox.com/~skeet/csharp/events.html

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Sep 12 '06 #10

"Jon Skeet [C# MVP]" <sk***@pobox.comwrote in message
news:MP***********************@msnews.microsoft.co m...
Hoop <jc******@oshtruck.comwrote:
>Yes, that looks like what I want to try.
I am having trouble with setting up the event to run.

After adding that code to the HiResTimer(),
In my main form, pressureForm, in the constructor, I do

public pressureForm()
{
startTimer()
}

startTimer()
{
MyTimer.HiResTimer.Start();

//Error, the name Expired does not exist in the current context
MyTimer.HiResTimer.ElapasedTime += new EventHandler(Expired);

}

Must not be exact way to do it.
Then use a custom event:

public EventHandler Expired
{
add { MyTimer.HiResTimer.ElapasedTime += value; }
remove { MyTimer.HiResTimer.ElapasedTime -= value; }
}
Sep 12 '06 #11
Hi,
Thanks for the help and direction guys.
I will look all this over.
Helps alot.
Jeff

Ben Voigt wrote:
"Jon Skeet [C# MVP]" <sk***@pobox.comwrote in message
news:MP***********************@msnews.microsoft.co m...
Hoop <jc******@oshtruck.comwrote:
Yes, that looks like what I want to try.
I am having trouble with setting up the event to run.

After adding that code to the HiResTimer(),
In my main form, pressureForm, in the constructor, I do

public pressureForm()
{
startTimer()
}

startTimer()
{
MyTimer.HiResTimer.Start();

//Error, the name Expired does not exist in the current context
MyTimer.HiResTimer.ElapasedTime += new EventHandler(Expired);

}

Must not be exact way to do it.

Then use a custom event:

public EventHandler Expired
{
add { MyTimer.HiResTimer.ElapasedTime += value; }
remove { MyTimer.HiResTimer.ElapasedTime -= value; }
}
Sep 12 '06 #12

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

Similar topics

10
by: Dee | last post by:
Is C++ the best language to create a Windows based Instant Messenger? Something along the lines of MSN Messenger, ICQ, Yahoo Chat, etc? Are there any downloadable full or trial SDK's out there?...
2
by: Ben | last post by:
My current project requires me to create part of a form that is created on the fly. The project consists a list of entries to an event. The name and address and such is easy. The design is detup so...
1
by: Ben | last post by:
Due to problems reading the first thread I started I think I should respond with a new post. I have been only able to read up to the 2nd clarification that I posted. Thanks to all who responded....
2
by: Anand Sagar | last post by:
I have a Panel1 and button1 on my webform. At runtime, I create 2 textboxes. I do it at the Page_Load event. I put the code within the " If Not isPostBack" For the button click event, I will do...
12
by: Mats Lycken | last post by:
Hi, I'm creating a CMS that I would like to be plug-in based with different plugins handling different kinds of content. What I really want is to be able to load/unload plugins on the fly without...
2
by: Dan | last post by:
I have need to create a com server that will fire events back to clients. I have looked at some of the documentation and I am new to Python so cant quite get it. I have created an IDL file of the...
16
by: tshad | last post by:
This is a little complicated to explain but I have some web services on a machine that work great. The problem is that I have run into a situation where I need to set up my program to access one...
1
by: skyson2ye | last post by:
Hi, guys: I have written a piece of code which utilizes Javascript in PHP to create a three level dynamic list box(Country, States/Province, Market). However, I have encountered a strange problem,...
1
by: Tony Johansson | last post by:
Hello! I'm reading in a book and here they says. "Now it is time to begin thinking about which events the control should provide. Because the control is derived from userControl class, it has...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
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...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.