473,396 Members | 2,061 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,396 software developers and data experts.

How to construct a Timer object in a class library

Howdy all,

I would like to know how can I insert a Timer object in my class
library?
This timer object will start and stop in a determinated part or event
of my program.

I know how to do this in Delphi or using a RAD tool and insert the
Timer object in a form, but how to do in C# by hand and in a class
library (without form), I don't know.

If it is possible for you, can you show me an example?

Regards,

Marcelo Muzilli

Jun 1 '06 #1
5 4897
Hey there Marcelo,

To create a timer object in your class you will need to add a reference to
System.Windows.Forms in the project and then create a new timer:

System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();

hope that helps!

"mu*****@sercomtel.com.br" wrote:
Howdy all,

I would like to know how can I insert a Timer object in my class
library?
This timer object will start and stop in a determinated part or event
of my program.

I know how to do this in Delphi or using a RAD tool and insert the
Timer object in a form, but how to do in C# by hand and in a class
library (without form), I don't know.

If it is possible for you, can you show me an example?

Regards,

Marcelo Muzilli

Jun 1 '06 #2
Hi Justin,

will this work for .NET compact framework. This class will run for a
handheld.

Thanks,

MM

MSFT Justin Swan wrote:
Hey there Marcelo,

To create a timer object in your class you will need to add a reference to
System.Windows.Forms in the project and then create a new timer:

System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();

hope that helps!

"mu*****@sercomtel.com.br" wrote:
Howdy all,

I would like to know how can I insert a Timer object in my class
library?
This timer object will start and stop in a determinated part or event
of my program.

I know how to do this in Delphi or using a RAD tool and insert the
Timer object in a form, but how to do in C# by hand and in a class
library (without form), I don't know.

If it is possible for you, can you show me an example?

Regards,

Marcelo Muzilli


Jun 1 '06 #3
Indeed, timer is supported by the compact framework so you shouldn't have a
problem with this.

"mu*****@sercomtel.com.br" wrote:
Hi Justin,

will this work for .NET compact framework. This class will run for a
handheld.

Thanks,

MM

MSFT Justin Swan wrote:
Hey there Marcelo,

To create a timer object in your class you will need to add a reference to
System.Windows.Forms in the project and then create a new timer:

System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();

hope that helps!

"mu*****@sercomtel.com.br" wrote:
Howdy all,

I would like to know how can I insert a Timer object in my class
library?
This timer object will start and stop in a determinated part or event
of my program.

I know how to do this in Delphi or using a RAD tool and insert the
Timer object in a form, but how to do in C# by hand and in a class
library (without form), I don't know.

If it is possible for you, can you show me an example?

Regards,

Marcelo Muzilli


Jun 1 '06 #4
Good, so could you show me an example?

I know that we have to declare a System.Threading and the Timer object
cames from this hierarchy but the problem is that I don't know how.

Have we to declare the Timer by hand instead of use the Timer object
form?
I saw the declaration in this link:
http://msdn.microsoft.com/library/de...classtopic.asp

For a Class Library, is not possible to use the System.Windows
declaration.

Many thanks,

MM
Justin Swan (MSFT) wrote:
Indeed, timer is supported by the compact framework so you shouldn't have a
problem with this.

"mu*****@sercomtel.com.br" wrote:
Hi Justin,

will this work for .NET compact framework. This class will run for a
handheld.

Thanks,

MM

MSFT Justin Swan wrote:
Hey there Marcelo,

To create a timer object in your class you will need to add a reference to
System.Windows.Forms in the project and then create a new timer:

System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();

hope that helps!

"mu*****@sercomtel.com.br" wrote:

> Howdy all,
>
> I would like to know how can I insert a Timer object in my class
> library?
> This timer object will start and stop in a determinated part or event
> of my program.
>
> I know how to do this in Delphi or using a RAD tool and insert the
> Timer object in a form, but how to do in C# by hand and in a class
> library (without form), I don't know.
>
> If it is possible for you, can you show me an example?
>
> Regards,
>
> Marcelo Muzilli
>
>



Jun 1 '06 #5
Howdy all,

I found the solution and I will post here for future search in this
topic. I created a MyTimer class outside of my main class. Inside my
main class I created a new instance of the MyTimer class and work with
the methods Start and Stop inside my main class.

The MyTimer code is here:

/*************************************/
using System;
using System.Threading;

namespace DexCommunicator
{
/// <summary>
/// Summary description for StopWatch.
/// </summary>

public class MyTimer
{

private DateTime startTime;
private DateTime stopTime;
private bool running = false;
public void Start()
{
this.startTime = DateTime.Now;
this.running = true;
}
public void Stop()
{
this.stopTime = DateTime.Now;
this.running = false;
}
//elaspsed time in milliseconds
public double GetElapsedTime()
{
TimeSpan interval;
if (running)
{
interval = DateTime.Now - startTime;
}
else
{
interval = stopTime - startTime;
}
return interval.TotalMilliseconds;
}
//elaspsed time in seconds
public double GetElapsedTimeSecs()
{
TimeSpan interval;
if (running)
{
interval = DateTime.Now - startTime;
}
else
{
interval = stopTime - startTime;
}
return interval.TotalSeconds;
}
}
}
/*************************************/
Thanks,

Marcleo Muzilli
mu*****@sercomtel.com.br wrote:
Good, so could you show me an example?

I know that we have to declare a System.Threading and the Timer object
cames from this hierarchy but the problem is that I don't know how.

Have we to declare the Timer by hand instead of use the Timer object
form?
I saw the declaration in this link:
http://msdn.microsoft.com/library/de...classtopic.asp

For a Class Library, is not possible to use the System.Windows
declaration.

Many thanks,

MM
Justin Swan (MSFT) wrote:
Indeed, timer is supported by the compact framework so you shouldn't have a
problem with this.

"mu*****@sercomtel.com.br" wrote:
Hi Justin,

will this work for .NET compact framework. This class will run for a
handheld.

Thanks,

MM

MSFT Justin Swan wrote:
> Hey there Marcelo,
>
> To create a timer object in your class you will need to add a reference to
> System.Windows.Forms in the project and then create a new timer:
>
> System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();
>
> hope that helps!
>
> "mu*****@sercomtel.com.br" wrote:
>
> > Howdy all,
> >
> > I would like to know how can I insert a Timer object in my class
> > library?
> > This timer object will start and stop in a determinated part or event
> > of my program.
> >
> > I know how to do this in Delphi or using a RAD tool and insert the
> > Timer object in a form, but how to do in C# by hand and in a class
> > library (without form), I don't know.
> >
> > If it is possible for you, can you show me an example?
> >
> > Regards,
> >
> > Marcelo Muzilli
> >
> >


Jun 2 '06 #6

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

Similar topics

6
by: Jim H | last post by:
I have a class object that creates and uses a System.Threading.Timer. In the destructor for my class I cancel the timer using timer.Change(infinite, infinite) then I call timer.Dispose() to clean...
3
by: rodchar | last post by:
hey all, if i have a timer program that ticks every 1/100th of a second and it just checks a variable status would that be a huge hit on the performance of the system or whatever indicator the...
11
by: Philip Wagenaar | last post by:
Hello, I am using a timer object in my Windows Forms Application. Does the code in ..elapsed event run in a diffrent thread? If the interval is set to 10 milliseconds and the time to execute the...
6
by: Michael C | last post by:
I've created a timer object and set it running without keeping a reference to it and not stopping it. Shouldn't the garbage collector pick up that there's no reference to the timer, call finalize...
12
by: Gina_Marano | last post by:
I have created an array of timers (1-n). At first I just created windows form timers but I read that system timers are better for background work. The timers will just be monitoring different...
5
by: Tony Gravagno | last post by:
I have a class that instantiates two Timer objects that fire at different intervals. My class can be instantiated within a Windows Form or from a Windows Service. Actions performed by one of the...
4
by: Lauren Quantrell | last post by:
I have just put together a vb.net app and now need to provide it to users. This application needs to run the code in a sub every 60 seconds from a Windows Service application. I have the...
11
by: Hotrod2000 | last post by:
I'm quite new to programming but I'm having problems getting a timer to work in visual studio.net I've created a timer on a form, enabled it and then typed the following code (from the mdsn...
3
by: Steve | last post by:
Hi All I am using VB.net 2008 and use timer controls within my applications Question Does the code in a Timer control.tick event run on a different thread to the main Application thread (UI...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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,...

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.