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 know when ThreadPoll is finish?

How to know when ThreadPoll is finish?

Scheduled Pinned Locked Moved C#
tutorialquestion
5 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.
  • S Offline
    S Offline
    Snowjim
    wrote on last edited by
    #1

    Hey! I am using the following code in a event(SerialPort.RecivedData event) that fires whenever data is written to a stream(serialPort) if (RUNNING) { ThreadPool.QueueUserWorkItem(new WaitCallback(onDataReceived)); currentRunningThreads++; } in OnDatareceived the serialPort is used to read the existing data. Now i need to close this serialPort, but i get errors without any source to show? I am setting Running to false, but that is not solving it? How can a see when the ThreadPools threads realy is finish with theres jobb? Best Regards Snowjim

    S J S 3 Replies Last reply
    0
    • S Snowjim

      Hey! I am using the following code in a event(SerialPort.RecivedData event) that fires whenever data is written to a stream(serialPort) if (RUNNING) { ThreadPool.QueueUserWorkItem(new WaitCallback(onDataReceived)); currentRunningThreads++; } in OnDatareceived the serialPort is used to read the existing data. Now i need to close this serialPort, but i get errors without any source to show? I am setting Running to false, but that is not solving it? How can a see when the ThreadPools threads realy is finish with theres jobb? Best Regards Snowjim

      S Offline
      S Offline
      Snowjim
      wrote on last edited by
      #2

      A more Specified error message: First a MessageBox that says that there is no source code to be displayed. Then a smaller box appers Title: ObjectDisposedException was unhandled safe handler has been closed I do have try and catch on every method i have but this exception is never runned(if it would i could see where the error is appering in my code)

      1 Reply Last reply
      0
      • S Snowjim

        Hey! I am using the following code in a event(SerialPort.RecivedData event) that fires whenever data is written to a stream(serialPort) if (RUNNING) { ThreadPool.QueueUserWorkItem(new WaitCallback(onDataReceived)); currentRunningThreads++; } in OnDatareceived the serialPort is used to read the existing data. Now i need to close this serialPort, but i get errors without any source to show? I am setting Running to false, but that is not solving it? How can a see when the ThreadPools threads realy is finish with theres jobb? Best Regards Snowjim

        J Offline
        J Offline
        jklucker
        wrote on last edited by
        #3

        One solution would be to create an event CloseSerialPort and call it from the onDataReceived method when it has finished it's job. Then you could put all the code needed to close your serial port in the event handler. I reject your reality and substitute my own! - Adam Savage, Mythbuster -George W Bush life is like a roll of toilet paper. The closer it gets to the end, the faster it goes.

        S 1 Reply Last reply
        0
        • S Snowjim

          Hey! I am using the following code in a event(SerialPort.RecivedData event) that fires whenever data is written to a stream(serialPort) if (RUNNING) { ThreadPool.QueueUserWorkItem(new WaitCallback(onDataReceived)); currentRunningThreads++; } in OnDatareceived the serialPort is used to read the existing data. Now i need to close this serialPort, but i get errors without any source to show? I am setting Running to false, but that is not solving it? How can a see when the ThreadPools threads realy is finish with theres jobb? Best Regards Snowjim

          S Offline
          S Offline
          S Senthil Kumar
          wrote on last edited by
          #4

          Instead of directly using ThreadPool, you can try wrapping OnDataReceived in a delegate and calling BeginInvoke on the delegate. That'll allow you to pass a callback that'll get called once OnDataReceived completes. Even otherwise, BeginInvoke returns an IAsyncResult that has a bool property IsCompleted that you can query to find out if the method has completed. Regards Senthil _____________________________ My Blog | My Articles | WinMacro

          1 Reply Last reply
          0
          • J jklucker

            One solution would be to create an event CloseSerialPort and call it from the onDataReceived method when it has finished it's job. Then you could put all the code needed to close your serial port in the event handler. I reject your reality and substitute my own! - Adam Savage, Mythbuster -George W Bush life is like a roll of toilet paper. The closer it gets to the end, the faster it goes.

            S Offline
            S Offline
            Snowjim
            wrote on last edited by
            #5

            How do i know when to call this CloseSerialPort in onDataReceived method? consider this: SerialPort.RecievedData event is triggerd Job is added to the threadpool that points to the onDataReveived method SerialPort.RecievedData event is triggerds 5 times and diffrent threads are working there way thow onDataReceived that contains a look part. By this i will not know what thread that is the last one. I need to close this threads before i can call serialport.close();

            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