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. How can thread retruns a value?

How can thread retruns a value?

Scheduled Pinned Locked Moved C#
question
5 Posts 4 Posters 0 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.
  • M Offline
    M Offline
    mrcooll
    wrote on last edited by
    #1

    m trying to start a thread has a parameters and returns an integer value. This is So Wrong... Thread t1 = new Thread(new ThreadStart(ConnectToDB)); int empId = t1.Start(); ConnectToDB(); private int ConnectToDB(int userName,int passWord) { SomeWebService.Users user = new SomeWebService.Users(); int employeeId = user.Login(userName, passWord); } but How can i do it?

    C C 2 Replies Last reply
    0
    • M mrcooll

      m trying to start a thread has a parameters and returns an integer value. This is So Wrong... Thread t1 = new Thread(new ThreadStart(ConnectToDB)); int empId = t1.Start(); ConnectToDB(); private int ConnectToDB(int userName,int passWord) { SomeWebService.Users user = new SomeWebService.Users(); int employeeId = user.Login(userName, passWord); } but How can i do it?

      C Offline
      C Offline
      Cracked Down
      wrote on last edited by
      #2

      You should use BackgroundWorker Component added in the version 2.0! this will solve your purpose! :)

      M 1 Reply Last reply
      0
      • C Cracked Down

        You should use BackgroundWorker Component added in the version 2.0! this will solve your purpose! :)

        M Offline
        M Offline
        mrcooll
        wrote on last edited by
        #3

        i have never used it :(( and i will be more than happy to explain how to!:rose:

        L 1 Reply Last reply
        0
        • M mrcooll

          i have never used it :(( and i will be more than happy to explain how to!:rose:

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          private void btnStart_Click(object sender, EventArgs e)
          {
          backgroundWorker1.RunWorkerAsync();
          }

          private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
          {
          [..do some work..]

          // When done, return the value. 
          e.Result = "Hello world from backgroundworker";
          

          }

          private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
          {
          // Here you get the returnvalue from the thread, and you
          // can use it in your Form1-thread :)
          string returnValue = (string)e.Result;
          }

          --edited, typo--

          I are troll :)

          1 Reply Last reply
          0
          • M mrcooll

            m trying to start a thread has a parameters and returns an integer value. This is So Wrong... Thread t1 = new Thread(new ThreadStart(ConnectToDB)); int empId = t1.Start(); ConnectToDB(); private int ConnectToDB(int userName,int passWord) { SomeWebService.Users user = new SomeWebService.Users(); int employeeId = user.Login(userName, passWord); } but How can i do it?

            C Offline
            C Offline
            Calin Tatar
            wrote on last edited by
            #5

            Or you may asynchronously invoke your method by using delegates. here is a sample[^] Calin

            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