Part of my program consists of a series of steps that either complete, or time out after a certain interval. Test conditions vary widely. How do I write a single function to encapsulate all possibilities?

To do that I'd ideally need to pass the necessary condition to the function to be evaluated *within* the function, rather than to be evaluated as a parameter and then passed to the function.

This is what I would ideally want (greatly simplified):

```
Private Function TestCondition(<CONDITION>) as Boolean 
  ' Returns True if <CONDITION> fulfilled within 10 seconds
  Dim sw as New Diagnostics.StopWatch
  sw.Start()
  While sw.ElapsedMilliseconds < 10000
    If <CONDITION> Return True
    System.Threading.Thread.Sleep(500)
  End While
  sw.Stop()
  Return False
End Function

```

Function should work with any expression that returns a boolean value:

```
TestCondition(x=5)
TestCondition(System.IO.File.Exists("myfile")

```

Obviously, the above doesn't work as the *results* of specified conditions are passed to the function, rather than the conditions themselves.

Based on other reading, I can likely accomplish this by:

* Restructuring my code
* Using delegates
* Using lambda expressions

but I still do not see exactly how.

Thanks a lot for your help!