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.WriteLi ne(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.AutoRese t = 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 7840
Hello jam,
There are three kinds of Timer in .Net totally for different
environment,whi ch is under different namespace, namely System.Threadin g,
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.WriteLi ne(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.AutoRese t = 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
'SiteStagerDotN et.SiteStager.T ickHandler(obje ct,
System.Timers.E lapsedEventArgs )'
Any clue?
code:
int numbertext =0;
private void TickHandler(obj ect sender, ElapsedEventArg s e)
{
Console.WriteLi ne(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.AutoRese t = false ;
// add handler
kicker.Elapsed += new ElapsedEventHan dler(TickHandle r) ;
// 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******** ******@TK2MSFTN GP12.phx.gbl
¤¤¼¶¼g... Hello jam, There are three kinds of Timer in .Net totally for different environment,whi ch is under different namespace, namely System.Threadin g, 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.WriteLi ne(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.AutoRese t = 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
ElapsedEventHan dler.
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 'SiteStagerDotN et.SiteStager.T ickHandler(obje ct, System.Timers.E lapsedEventArgs )'
Any clue? code: int numbertext =0; private void TickHandler(obj ect sender, ElapsedEventArg s e) { Console.WriteLi ne(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.AutoRese t = false ;
// add handler kicker.Elapsed += new ElapsedEventHan dler(TickHandle r) ;
// 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******** ******@TK2MSFTN GP12.phx.gbl ¤¤¼¶¼g... Hello jam, There are three kinds of Timer in .Net totally for different environment,whi ch is under different namespace, namely System.Threadin g, 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.WriteLi ne(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.AutoRese t = 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 interval of the timer at
run time and then stop the timer the program will freeze, it doesn't
actually crash (no error dialog comes up) but it will sit there forever
number crunching but the UI doesn't do anything.
Any ideas related to this problem...
|
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 this, make the
elapsed time equal to 10000. So, only after 10 seconds, should the
timer_elapsed event be fired, but no.
Does anyone had the same problem?
|
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 go off every 2 minutes if the
files are done or not? Here is the code:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
|
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 seconds... And so on... Here
is my unworking below code:
Anyhelp would be greatly appreciated...
Thank you indeed...
Cem Louis
|
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 = ds.Tables(0).Rows(0).Item("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 problem is it
doesn't appear to be running any of my code whatsoever.
I dropped a Timer Control on the designer, set it to disabled with an
interval of 5000, went to the code window and on the OnStart Event,
typed in:
Timer1.Enabled=True
|
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 doesn't stop, but it
seems the timer process stops. Has anyone else run into this? What have
been solutions?
|
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 occurs with Windows 7 running on a dual core processor, single core and under the virtual pc on any processor works.
I have attached a test program to show this problem. The program uses 2 timers to count down to 0. It does not matter what type...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |