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. Get Thread Result (IAsyncResult)

Get Thread Result (IAsyncResult)

Scheduled Pinned Locked Moved C#
helpquestionlearning
4 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.
  • P Offline
    P Offline
    Patricio Tapia
    wrote on last edited by
    #1

    public bool resultado() { ... ... ... return true; } let's say that i'm created a Thread and i run the resultado method. How i can capture the result? msdn didn't help me :doh: (and, of course, stop the Thread)

    M L 2 Replies Last reply
    0
    • P Patricio Tapia

      public bool resultado() { ... ... ... return true; } let's say that i'm created a Thread and i run the resultado method. How i can capture the result? msdn didn't help me :doh: (and, of course, stop the Thread)

      M Offline
      M Offline
      Mandaar Kulkarni
      wrote on last edited by
      #2

      check this out http://authors.aspalliance.com/aspxtreme/sys/IAsyncResultClass.aspx[^]

      1 Reply Last reply
      0
      • P Patricio Tapia

        public bool resultado() { ... ... ... return true; } let's say that i'm created a Thread and i run the resultado method. How i can capture the result? msdn didn't help me :doh: (and, of course, stop the Thread)

        L Offline
        L Offline
        lmoelleb
        wrote on last edited by
        #3

        A thread terminates when it has no more code to execute (it gets to the end of the method you set as it's start method). You REALLY need to understand how threads interact or you will just spend your entire time debugging things you do not know anything about. Read some tutorials, for example this one: MSDN[^] Generally speaking you communicate with one of the following methods: 1) Communicate with Events (ManualResetEvent, AutoResetEvent). This is typically used to signal things like "data inserted in queue", "terminate" etc. The advantage is that a thread can wait for an event to be raised without consuming CPU resources. 2) Shared data protected by locks. For example a queue one thread is inserting in while another thread reads, or the tread setting a value on a "result object" passed to it. Simple datatypes (int, bool etc) can be marked by the keyword "volatile" instead of using a lock for each access. 3) Invoking from your subtread to the main thread (look at the Dispatcher object, or the old WinForm.Invoke stuff). This allows updating for example a WinForm userinterface where only the GUI thread is allowed to change control values, but is also a pretty sollid way to ensure data is only manipulated on one thread which means you do not need to do locks (as long as you make sure the worker thread is always working on a copy of the data). Instead of setting a terminate event you can allso raise a ThreadInterupt exception, but please notice a thread will NOT interrupt while executing your code - it will ONLY interrupt from a safe state, like waiting for an event... and in that case you can as well have it wait for a terminate event as well. :)

        P 1 Reply Last reply
        0
        • L lmoelleb

          A thread terminates when it has no more code to execute (it gets to the end of the method you set as it's start method). You REALLY need to understand how threads interact or you will just spend your entire time debugging things you do not know anything about. Read some tutorials, for example this one: MSDN[^] Generally speaking you communicate with one of the following methods: 1) Communicate with Events (ManualResetEvent, AutoResetEvent). This is typically used to signal things like "data inserted in queue", "terminate" etc. The advantage is that a thread can wait for an event to be raised without consuming CPU resources. 2) Shared data protected by locks. For example a queue one thread is inserting in while another thread reads, or the tread setting a value on a "result object" passed to it. Simple datatypes (int, bool etc) can be marked by the keyword "volatile" instead of using a lock for each access. 3) Invoking from your subtread to the main thread (look at the Dispatcher object, or the old WinForm.Invoke stuff). This allows updating for example a WinForm userinterface where only the GUI thread is allowed to change control values, but is also a pretty sollid way to ensure data is only manipulated on one thread which means you do not need to do locks (as long as you make sure the worker thread is always working on a copy of the data). Instead of setting a terminate event you can allso raise a ThreadInterupt exception, but please notice a thread will NOT interrupt while executing your code - it will ONLY interrupt from a safe state, like waiting for an event... and in that case you can as well have it wait for a terminate event as well. :)

          P Offline
          P Offline
          Patricio Tapia
          wrote on last edited by
          #4

          Thanks You i'm working with basic Threads, like Thread obj = new Thread(method); but now i need to expand my brain =) reading msdn =)

          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