Tech Off Thread

2 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

Parsing 2 parameters to a thread?

Back to Forum: Tech Off
  • User profile image
    Chadk

    I don't really know how to parse 2(Not 0, not 1, but 2!) parameters, when i start a thread(Using C# 2.0'). Any ideas how to do this? Smiley

  • User profile image
    littleguru

    Chadk wrote:

    I don't really know how to parse 2(Not 0, not 1, but 2!) parameters, when i start a thread(Using C# 2.0'). Any ideas how to do this? Smiley



    Hmmm. NET 2.0 makes it actually really easy:

    public static class Program

    {

    public static void Main()

    {

    Foo foo = new Foo();

    foo.Foo1 = "test";

    foo.Foo2 = 2;

    Thread thread = new Thread(new ParameterizedThreadStart(MyThread));

    thread.Start(foo);

    }

    public static void MyThread(object foo)

    {

    Foo f = (Foo)foo;

    MessageBox.Show(string.Format("Foo1: {0}, Foo2: {1}", f.Foo1, f.Foo2));

    }

    }

    public sealed class Foo

    {

    public string Foo1;

    public int Foo2;

    }

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.