Link to home
Start Free TrialLog in
Avatar of margarit
margaritFlag for Israel

asked on

System.Windows.Forms.Timer GetBoardTypeConnected;

Hello,

I  have problems with the following code.
I wanted to enter the "GetBoardTypeFunc" only once, therefore in this function I stop the timer.
Although I stopped the timer I see that I continue to enter the "GetBoardTypeFunc" function.
Why?
Should I unsubscribe from the event EventHandler(GetBoardTypeFunc)?
If yes, what is a sintax?

THANKS
Margarit
System.Windows.Forms.Timer GetBoardTypeConnected;
//////////////////////////////////////////////////////////////////////////////////////////////////////
private void GetBoardType()
        {
            GetBoardTypeConnected = new System.Windows.Forms.Timer();
            GetBoardTypeConnected.Interval = 400;// 250;
            GetBoardTypeConnected.Start();
            GetBoardTypeConnected.Tick += new EventHandler(GetBoardTypeFunc);
        }
 
 private void GetBoardTypeFunc(Object state, EventArgs eArgs)
        {
            a++;
            GetBoardTypeConnected.Stop();
            GetBoardTypeConnected.Dispose();
        }
///////////////////////////////////////////////////////////////////////////////////////////////////////////

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of margarit

ASKER

Thanks! The solution worked for me. This function was called more than once from another event.