TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
lindroosj
NA
3
0
How can this be?
Mar 25 2005 4:41 PM
Look at this code. When I run it, pushing the button should create a new object, and the old should be deleted, but thats not what happening. Compile the code and try it. How can this be? /J Lindroos using System.Timers; using System; using System.Windows.Forms; using System.Drawing; public interface ITimerListener { void Tick(int seconds); } public class TimerClass { System.Timers.Timer t=null; int seconds; ITimerListener listener; public TimerClass(ITimerListener listener) { seconds=0; this.listener=listener; t=new System.Timers.Timer(); t.Elapsed+=new ElapsedEventHandler(Tick); t.Interval=1000; t.Enabled=true; Console.WriteLine("New timerclass"); } public void Tick(object source, ElapsedEventArgs e) { seconds++; listener.Tick(seconds); } } public class TestClass : ITimerListener { TimerClass tc; public TestClass() { //Making the form and the button Form f=new Form(); f.Size=new Size(100,100); Button b=new Button(); b.Text="Start timer"; b.Size=new Size(90,32); b.Location=new Point(5,32); b.Click+=new EventHandler(b_Click); f.Controls.Add(b); f.ShowDialog(); } public void b_Click(object sender, EventArgs e) { //Creating a NEW TimerClass tc=new TimerClass(this); } public void Tick(int seconds) { //Writing the seconds Console.WriteLine(seconds); } public static void Main(string[] args) { TestClass t=new TestClass(); } }
Reply
Answers (
1
)
Hotkey
how our program knows workstation is connected to server