By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,194 Members | 1,668 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,194 IT Pros & Developers. It's quick & easy.

How to construct a Timer object in a class library

P: n/a
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
Share this Question
Share on Google+
5 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.