Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Passing Objects to threads..

Passing Objects to threads..

Scheduled Pinned Locked Moved C#
questioncsharp
8 Posts 5 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    Eytukan
    wrote on last edited by
    #1

    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.

    M A 2 Replies Last reply
    0
    • E Eytukan

      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.

      M Offline
      M Offline
      Manas Bhardwaj
      wrote on last edited by
      #2

      You can use the static variables for this.

      C 1 Reply Last reply
      0
      • M Manas Bhardwaj

        You can use the static variables for this.

        C Offline
        C Offline
        Colin Angus Mackay
        wrote on last edited by
        #3

        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

        M A 2 Replies Last reply
        0
        • C Colin Angus Mackay

          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

          M Offline
          M Offline
          Manas Bhardwaj
          wrote on last edited by
          #4

          Didnt get you :confused: How can you have threads starting at once?

          C 1 Reply Last reply
          0
          • C Colin Angus Mackay

            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

            A Offline
            A Offline
            AikinX
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0
            • M Manas Bhardwaj

              Didnt get you :confused: How can you have threads starting at once?

              C Offline
              C Offline
              Colin Angus Mackay
              wrote on last edited by
              #6

              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

              M 1 Reply Last reply
              0
              • C Colin Angus Mackay

                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

                M Offline
                M Offline
                Manas Bhardwaj
                wrote on last edited by
                #7

                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

                1 Reply Last reply
                0
                • E Eytukan

                  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.

                  A Offline
                  A Offline
                  andre_swnpl
                  wrote on last edited by
                  #8

                  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();

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups