Felice Massaro

Felice Massaro

  • NA
  • 17
  • 7.8k

Passing variables to timer event in a class from Form1 Butto

Jun 4 2013 12:09 PM

I have a method in a class that receives and returns multiple parameters from/to Form1. I need to use a timed event to execute some code using those parameters. I have arranged this simplified code to show the dynamic:

class Motor
{
    public static System.Timers.Timer _timer;
    int valReg = 30;

    public void PID(decimal _actualSpeed, Decimal _speedRequest, out Decimal _pwmAuto, out decimal _preValReg)
    {

        _timer = new System.Timers.Timer();
        _timer.Interval = (3000);
        _timer.Elapsed += new System.Timers.ElapsedEventHandler(_timerAutoset);
        _timer.Enabled = true;
        // {....}
        _pwmAuto = valReg;
        _preValReg = valReg - 1;
    }
    static void _timerAutoset(object sender, System.Timers.ElapsedEventArgs e)
    {
        /* here I need to work with:
         _actualSpeed
         _speedRequest
         _pwmAuto
         _preValReg
        and send back the last two variables
         */
    }    
}

This is how I pass and receive the variables from Form1 button :

        private void button4_Click(object sender, EventArgs e)
        {
        // some code ................
        Motor mtr = new Motor();
        mtr.PID(speedRequest, actualSpeed, out pwmAuto, out xxx);
        //..more code

How can I pass/get back those parameters to/from _timerAutoset event?


Answers (1)