It sounds like the stateTimer object is being declared in the scope of
your start button code. You'll need to declare it more global in the
scope of your class so that the stop button code has visibility of
the object.
using System;
using System.Drawing;
using System.Collecti ons;
using System.Componen tModel;
using System.Windows. Forms;
using System.Data;
using System.Threadin g;
namespace EnvVar
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class frmMain : System.Windows. Forms.Form
{
System.Threadin g.Timer oTimer; //visible to entire class code
int iCount;
private System.Windows. Forms.Button StartButton;
private System.Windows. Forms.Button StopButton;
/// <summary>
/// Required designer variable.
/// </summary>
private System.Componen tModel.Containe r components = null;
public frmMain()
{
//
// Required for Windows Form Designer support
//
InitializeCompo nent();
//
// TODO: Add any constructor code after InitializeCompo nent
call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Disp ose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeCompo nent()
{
this.StartButto n = new System.Windows. Forms.Button();
this.StopButton = new System.Windows. Forms.Button();
this.SuspendLay out();
//
// StartButton
//
this.StartButto n.Location = new System.Drawing. Point(208,
192);
this.StartButto n.Name = "StartButto n";
this.StartButto n.TabIndex = 0;
this.StartButto n.Text = "button1";
this.StartButto n.Click += new
System.EventHan dler(this.Start Button_Click);
//
// StopButton
//
this.StopButton .Location = new System.Drawing. Point(192,
232);
this.StopButton .Name = "StopButton ";
this.StopButton .TabIndex = 1;
this.StopButton .Text = "button2";
this.StopButton .Click += new
System.EventHan dler(this.StopB utton_Click);
//
// frmMain
//
this.AutoScaleB aseSize = new System.Drawing. Size(5, 13);
this.ClientSize = new System.Drawing. Size(292, 273);
this.Controls.A dd(this.StopBut ton);
this.Controls.A dd(this.StartBu tton);
this.Name = "frmMain";
this.Text = "Form1";
this.ResumeLayo ut(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run (new frmMain());
}
private void StartButton_Cli ck(object sender, System.EventArg s
e)
{
oTimer = new System.Threadin g.Timer( new
TimerCallback(a b), null, 1000, 1000 );
}
private void StopButton_Clic k(object sender, System.EventArg s
e)
{
oTimer.Dispose( );
}
public void ab( Object state )
{
iCount++;
}
}
}
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com