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
> >
> >