Passing Objects to threads..
-
How do I pass objects to threads? VS2005 let me say, t.start((object)obj); but VS2003 (1.1) doesnt. Why? How do I do that in .net 1.1?
Press: 1500 to 2,200 messages in just 6 days? How's that possible sir? **Dr.Brad :**Well,I just replied to everything Graus did and then argued with Negus for a bit.
-
How do I pass objects to threads? VS2005 let me say, t.start((object)obj); but VS2003 (1.1) doesnt. Why? How do I do that in .net 1.1?
Press: 1500 to 2,200 messages in just 6 days? How's that possible sir? **Dr.Brad :**Well,I just replied to everything Graus did and then argued with Negus for a bit.
You can use the static variables for this.
-
You can use the static variables for this.
And if you have multiple threads starting at once?
Upcoming events: * Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ... * Reading: Developer Day 5 Never write for other people. Write for yourself, because you have a passion for it. -- Marc Clifton My website
-
And if you have multiple threads starting at once?
Upcoming events: * Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ... * Reading: Developer Day 5 Never write for other people. Write for yourself, because you have a passion for it. -- Marc Clifton My website
Didnt get you :confused: How can you have threads starting at once?
-
And if you have multiple threads starting at once?
Upcoming events: * Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ... * Reading: Developer Day 5 Never write for other people. Write for yourself, because you have a passion for it. -- Marc Clifton My website
If threads need different parameters we can name each thread (or group of) and use static hash table (dictionary) to store the parameters. P.S. I think it is good way to solve this. But I have never worked with FW 1.1. May be it has a different recommended solution
-
Didnt get you :confused: How can you have threads starting at once?
In a multithreaded environment you can have mulitple things happening at the same time, especially in a multicore or multiprocessor environment. So, how does your solution work if you want to start several threads at the same time?
Upcoming events: * Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ... * Reading: Developer Day 5 Never write for other people. Write for yourself, because you have a passion for it. -- Marc Clifton My website
-
In a multithreaded environment you can have mulitple things happening at the same time, especially in a multicore or multiprocessor environment. So, how does your solution work if you want to start several threads at the same time?
Upcoming events: * Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ... * Reading: Developer Day 5 Never write for other people. Write for yourself, because you have a passion for it. -- Marc Clifton My website
In .Net 1.1 the ThreadStart never takes a parameter, so you the method which is called on a new thread will have to access the object stored some where else. But keep in mind to make thread safe. Though this is now possible in 2.0 using Annonymous Methods. Hope, it is clear now
-
How do I pass objects to threads? VS2005 let me say, t.start((object)obj); but VS2003 (1.1) doesnt. Why? How do I do that in .net 1.1?
Press: 1500 to 2,200 messages in just 6 days? How's that possible sir? **Dr.Brad :**Well,I just replied to everything Graus did and then argued with Negus for a bit.
you could do this: create a class that will execute on the thread. public class ThreadObj { private int t1; private string t2; public int T1 { get { return t1; } set { t1 = value; } } public string T2 { get { return t2; } set { t2 = value; } } public void MyThreadMethod() { string t = t2; } } then call this with : ThreadObj o = new ThreadObj(); o.T2 = "Hello"; o.T1 = 1; System.Threading.ThreadStart ts = new System.Threading.ThreadStart(o.MyThreadMethod); System.Threading.Thread tr = new System.Threading.Thread(ts); tr.Start();