title: C# Passing functions with parameters as delegates, possible?
body: <p>I have a System.Windows.Form.Timer()</p>
  <pre><code>myTimer = new System.Windows.Forms.Timer();
  myTimer.Interval = 100;
  myTimer.Tick += new EventHandler(TimerElapsed);
  </code></pre>
  <p>I want to be able the change the function that runs in the timer callback on the fly.
  Basically, I'm trying to poll a variable with a timeout, but I want that method for checking that variable to be able to change.
  For example:</p>
  <pre><code>public delegate bool MyFunction(string[] buffer, string str);
  static MyFunction timerFunction;
  static bool pollVariable
  
  private void TimerElapsed(object sender, EventArgs e)
          {
              timerCount++;
  
              pollVariable = timerFunction();                 //This doesn't work
              //pollVariable = timerFunction(myBuffer, str);  //This does, but only when I don't pass 
                                                              //any parameters in the Poll function below
          }
  
  private static void PollVaribaleWithTimeout(MyFunction f, int timeout) 
          {
              timerFunction = f;                              //Here is where I want to swap out the 
                                                              // functionality of the timer callback
  
              timerCount = 0;
              myTimer.Start();
              while(myTimer.enabled)
              {
                      if ((timerCount &gt;= timeout) || (pollVariable = true))
                      {
                          myTimer.Stop();
                      }
              }
          }
  
  </code></pre>
  <p>So at this stage I want to be able to define any number of functions that search a buffer for a certain string via some arbitrary means. So lets make searchFunc1 and searchFunc2.</p>
  <pre><code>private bool searchFunc1(string[] buffer, string str)
  {
          //do stuff
          return true; 
  }
  private bool searchFunc2(string[] buffer, string str)
  {
          //do stuff
          return false;    
  }
  </code></pre>
  <p>Then somewhere else I'd like to call the poll variable function passing through the specific search function with specific parameters specifying the buffers, strings and timeouts etc.</p>
  <pre><code>PollVariableWithTimeout(searchFunc1(thisBuffer, &quot;abc&quot;), 200);  //doesn't work
  PollVariableWithTimeout(searchFunc2(thatBuffer, &quot;123&quot;), 500);  //doesn't work
  //PollVariableWithTimeout(searchFunc1, 300);                   //This does work but doesn't provide me the 
                                                                 // functionality of being able to adjust the 
                                                                 // parameters at this level
  </code></pre>
  <p>Is this possible? Or am I barking up the wrong tree by expecting to call a function with parameters that includes a function with parameters?!
  Is there a better way to approach this.
  I'm reasonably new to C# coming from a background in C so some stuff regarding delegates is a bit confusing.</p>
  <p>Cheers for any help!
  Colm</p>