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 to return value from a thread

How to return value from a thread

Scheduled Pinned Locked Moved C#
questiontutorial
3 Posts 3 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.
  • A Offline
    A Offline
    anveshvm
    wrote on last edited by
    #1

    How can I return value from a thread?? Thanks in advance Anvesh

    L L 2 Replies Last reply
    0
    • A anveshvm

      How can I return value from a thread?? Thanks in advance Anvesh

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      Hi, there are many ways you can pass data to a thread, and retrieve results. For one, there is a possibility to pass an object to Thread.Start(); so you could store all the inputs in that object before you start the thread, and/or retrieve all the results once the thread is done. Or you could turn that around, and have a little class (say class Job), which you instantiate, pass parameters (thru properties maybe), then call its Run method (which launches a thread inside that class, invisible to the outside world), and finally gets the results available somehow (e.g. again as Properties). This is my preferred way; it makes it very easy to run several similar jobs at the same time, just by instatiating more Job objects and Run()ning them. :)

      Luc Pattyn [Forum Guidelines] [My Articles]


      Fixturized forever. :confused:


      1 Reply Last reply
      0
      • A anveshvm

        How can I return value from a thread?? Thanks in advance Anvesh

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

        You can use the class BackGroundWorker and handle the completed event and getting the property "Result" of the event args

        Saludos!! ____Juan

        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