ParameterizedThreadStart: Good call!

I just noticed that a new overload of the Thread constructor was added to .NET v2, accepting a ParameterizedThreadStart object. Cleverly enough, it allows you to call the thread's Start() method with a parameter to pass in to the method you're firing in its own thread. I don't understand why that wasn't there from the start, but good call!

2 Comments

  • You can only pass one parameter and your function must accept "object" for type. Next to that, to pass more parameters you have to use the delegate workaround. But it's a good start anyhow, it's better than nothing.

  • Public Class Parameters
    Public strParam as String
    Public intParam as Integer
    ... etc etc

    Then just pass in a copy of the parameters class. A few delegates and it makes a decent traffic conductor for pulling data in and out of threads too. It's way too bulky for fine grain threading, but works decently for long running stuff.

Comments have been disabled for this content.