James

James

  • NA
  • 7
  • 0

New To Programming - Why do i need to define an object for use with Threading.

Jul 23 2008 5:31 AM

Hey all,

I'm very new to programming (erm day 3 today) so i apologize if my terminology is wrong.

 I've been learning from a very good book. But i decided to go and learn a few things on my own. One of the main things that intrested me is multi threading.

I seemed to get how the basics worked. Untill i tried to start a method with paramiters. After some fiddleing and some googling i managed to get it working by changing my int value on the method to an object value.

My question is simply WHY do i need to define my variable as an object to make it work? I just cant seem to get my head around it. Why can i not do something like Thread tid1 = new Thread(bob.thead1(1000));

Code:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading;

namespace ConsoleApplication1

{

 

class Program

{

static void Main(string[] args)

{

doit bob = new doit();

Thread tid1 = new Thread(bob.thead1);

Thread tid2 = new Thread(bob.thead1);

Thread tid3 = new Thread(bob.thead1);

Thread tid4 = new Thread(bob.thead1);

tid1.Start(10);

tid2.Start(30);

tid3.Start(500);

tid4.Start(254);

}

}

class doit

{

public void thead1(Object val)

{

for (int i = 0; i < 50; i++)

{

Console.WriteLine("Processing " + i);

Thread.Sleep(Convert.ToInt32(val));

}

}

}

}

 

Thanks in advance.

James


Answers (4)