Dear all,
I am wrtiing a console application and doing some test on timer, the below
is my sample code I got from some site, but I cannot make it work...
Error is
'System.Timers.Timer' does not contain a definition for 'Tick'
So what should i do???
the final thing I wanna get is, I have a console will call a exe running in
background, and then I wanna check it is is still running ( Use get process
by name here to check if it is still running), then if running, check it
after 1 min.
Thx for helping.
Codes:
int numbertext =0;
void TickHandler( object sender, EventArgs e )
{
Console.WriteLine(numbertext);
numbertext ++;
}
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
// usage block
{
// create timer
Timer kicker = new Timer() ;
kicker.Interval = 1000 ;
kicker.AutoReset = false ;
// add handler
kicker.Tick += new EventHandler( TickHandler ) ;
// start timer
kicker.Start() ;
// change interval
kicker.Interval = 2000 ;
// stop timer
kicker.Stop() ;
// you can start and stop timer againg
kicker.Start() ;
kicker.Stop() ;
}
} 3 7784
Hello jam,
There are three kinds of Timer in .Net totally for different
environment,which is under different namespace, namely System.Threading,
System.Timers, System.Windows.Forms.
According to your aspect, you can only use the Elapsed event, because the
Tick event only exists in the Timer of System.Windows.Forms.
"jam" <hk***@hotmail.com> дÈëÏûÏ¢ÐÂÎÅ
:#G**************@tk2msftngp13.phx.gbl... Dear all,
I am wrtiing a console application and doing some test on timer, the below is my sample code I got from some site, but I cannot make it work... Error is 'System.Timers.Timer' does not contain a definition for 'Tick' So what should i do???
the final thing I wanna get is, I have a console will call a exe running
in background, and then I wanna check it is is still running ( Use get
process by name here to check if it is still running), then if running, check it after 1 min. Thx for helping.
Codes: int numbertext =0; void TickHandler( object sender, EventArgs e ) { Console.WriteLine(numbertext); numbertext ++; }
/// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main(string[] args) {
// usage block {
// create timer Timer kicker = new Timer() ; kicker.Interval = 1000 ; kicker.AutoReset = false ;
// add handler kicker.Tick += new EventHandler( TickHandler ) ;
// start timer kicker.Start() ;
// change interval kicker.Interval = 2000 ;
// stop timer kicker.Stop() ;
// you can start and stop timer againg kicker.Start() ; kicker.Stop() ;
}
}
Thx Alan,
I just found out that too, I modify the code as below, but still have error
An object reference is required for the nonstatic field, method, or property
'SiteStagerDotNet.SiteStager.TickHandler(object,
System.Timers.ElapsedEventArgs)'
Any clue?
code:
int numbertext =0;
private void TickHandler(object sender, ElapsedEventArgs e)
{
Console.WriteLine(numbertext);
numbertext ++;
}
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
// usage block
{
// create timer
Timer kicker = new Timer() ;
kicker.Interval = 1000 ;
kicker.AutoReset = false ;
// add handler
kicker.Elapsed += new ElapsedEventHandler(TickHandler) ;
// start timer
kicker.Start() ;
// change interval
kicker.Interval = 2000 ;
// stop timer
kicker.Stop() ;
// you can start and stop timer againg
kicker.Start() ;
kicker.Stop() ;
}
"Alan" <li***@channel.com> ¦b¶l¥ó news:ua**************@TK2MSFTNGP12.phx.gbl
¤¤¼¶¼g... Hello jam, There are three kinds of Timer in .Net totally for different environment,which is under different namespace, namely System.Threading, System.Timers, System.Windows.Forms. According to your aspect, you can only use the Elapsed event, because the Tick event only exists in the Timer of System.Windows.Forms.
"jam" <hk***@hotmail.com> дÈëÏûÏ¢ÐÂÎÅ :#G**************@tk2msftngp13.phx.gbl... Dear all,
I am wrtiing a console application and doing some test on timer, the
below is my sample code I got from some site, but I cannot make it work... Error is 'System.Timers.Timer' does not contain a definition for 'Tick' So what should i do???
the final thing I wanna get is, I have a console will call a exe running in background, and then I wanna check it is is still running ( Use get process by name here to check if it is still running), then if running, check it after 1 min. Thx for helping.
Codes: int numbertext =0; void TickHandler( object sender, EventArgs e ) { Console.WriteLine(numbertext); numbertext ++; }
/// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main(string[] args) {
// usage block {
// create timer Timer kicker = new Timer() ; kicker.Interval = 1000 ; kicker.AutoReset = false ;
// add handler kicker.Tick += new EventHandler( TickHandler ) ;
// start timer kicker.Start() ;
// change interval kicker.Interval = 2000 ;
// stop timer kicker.Stop() ;
// you can start and stop timer againg kicker.Start() ; kicker.Stop() ;
}
}
Hello jam,
Yes.Because the Main(...) is a static method.You have two options:
One is to construct one object which has the TickHandler method fit for
ElapsedEventHandler.
The other is to write one static TickHandler method.
"jam" <hk***@hotmail.com> дÈëÏûÏ¢ÐÂÎÅ
:#A**************@TK2MSFTNGP14.phx.gbl... Thx Alan,
I just found out that too, I modify the code as below, but still have
error An object reference is required for the nonstatic field, method, or
property 'SiteStagerDotNet.SiteStager.TickHandler(object, System.Timers.ElapsedEventArgs)'
Any clue? code: int numbertext =0; private void TickHandler(object sender, ElapsedEventArgs e) { Console.WriteLine(numbertext); numbertext ++; }
/// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main(string[] args) {
// usage block {
// create timer Timer kicker = new Timer() ; kicker.Interval = 1000 ; kicker.AutoReset = false ;
// add handler kicker.Elapsed += new ElapsedEventHandler(TickHandler) ;
// start timer kicker.Start() ;
// change interval kicker.Interval = 2000 ;
// stop timer kicker.Stop() ;
// you can start and stop timer againg kicker.Start() ; kicker.Stop() ;
} "Alan" <li***@channel.com> ¦b¶l¥ó
news:ua**************@TK2MSFTNGP12.phx.gbl ¤¤¼¶¼g... Hello jam, There are three kinds of Timer in .Net totally for different environment,which is under different namespace, namely System.Threading, System.Timers, System.Windows.Forms. According to your aspect, you can only use the Elapsed event, because
the Tick event only exists in the Timer of System.Windows.Forms.
"jam" <hk***@hotmail.com> дÈëÏûÏ¢ÐÂÎÅ :#G**************@tk2msftngp13.phx.gbl... Dear all,
I am wrtiing a console application and doing some test on timer, the below is my sample code I got from some site, but I cannot make it work... Error is 'System.Timers.Timer' does not contain a definition for 'Tick' So what should i do???
the final thing I wanna get is, I have a console will call a exe
running in background, and then I wanna check it is is still running ( Use get process by name here to check if it is still running), then if running, check
it after 1 min. Thx for helping.
Codes: int numbertext =0; void TickHandler( object sender, EventArgs e ) { Console.WriteLine(numbertext); numbertext ++; }
/// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main(string[] args) {
// usage block {
// create timer Timer kicker = new Timer() ; kicker.Interval = 1000 ; kicker.AutoReset = false ;
// add handler kicker.Tick += new EventHandler( TickHandler ) ;
// start timer kicker.Start() ;
// change interval kicker.Interval = 2000 ;
// stop timer kicker.Stop() ;
// you can start and stop timer againg kicker.Start() ; kicker.Stop() ;
}
}
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: xenny |
last post by:
Hi,
I'm developing a program in visual c++.NET and have got a problem. My
program will do background number crunching over and over again on a
timer event. My problem is if I change the...
|
by: Sergio Cardoso |
last post by:
Hello!
I have a application that uses the system.timer object. My big problem is
when the application starts, fire the elapsed event.
In the form_load event, i use the try command and inside...
|
by: DaveF |
last post by:
I am trying to write a service to fire an ftp object off. I want to wait 2
minutes and then download the files. Then repeat every 2 minutes. The files
just seem to stop downloading. Does that timer...
|
by: Cem Louis |
last post by:
Hi,
I have a listbox with three values on it and a button on my form. When
I pressed the button the listbox have to select the next item after 2
seconds. Then select the next one after 2...
|
by: Antti Laakso |
last post by:
Hi
i have function like above
Public Sub halytystutkinta()
Dim ds As New DataSet
ds = dl2.HaeHalytys()
Dim onkohal As Int16
onkohal = ds.Tables(0).Rows(0).Item("onkohalytys")
halid =...
|
by: Scott H |
last post by:
Hello,
I'm having a go at writing my first Windows Service in VB.NET and I'm
having a problem. I have it installed ok and started the service
sucessfully, I can stop it, and restart it fine, the...
|
by: Kevin Antel |
last post by:
We have written a service that uses a timer control to check for a process
every 60 seconds. This is installed on a Windows 2003 Server w/SP1.
The problem we are running into is that the service...
|
by: williambp |
last post by:
I have been writing visual basic and vb .net applications for years and have come across this problem with the timer component under Windows 7 32bit on dual core Intel processors. This problem only...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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,...
|
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...
|
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...
| |