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. Cancel on ThreadPool queued executions?

Cancel on ThreadPool queued executions?

Scheduled Pinned Locked Moved C#
comquestion
7 Posts 3 Posters 1 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.
  • D Offline
    D Offline
    devvvy
    wrote on last edited by
    #1

    Is it really impossible to cancel a queued item?[^]

    H L 2 Replies Last reply
    0
    • D devvvy

      Is it really impossible to cancel a queued item?[^]

      H Offline
      H Offline
      Harvey Saayman
      wrote on last edited by
      #2

      Smart Thread Pool[^] supports cancelation of queued items.

      Harvey Saayman - South Africa Software Developer .Net, C#, SQL you.suck = (you.Occupation == jobTitles.Programmer && you.Passion != Programming) 1000100 1101111 1100101 1110011 100000 1110100 1101000 1101001 1110011 100000 1101101 1100101 1100001 1101110 100000 1101001 1101101 100000 1100001 100000 1100111 1100101 1100101 1101011 111111

      D 1 Reply Last reply
      0
      • D devvvy

        Is it really impossible to cancel a queued item?[^]

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

        The standard ThreadPool holds threads for you to use; you never get full control over those threads, so there are a lot of managerial operations you can't perform on them, such as changing their priority, or aborting them. What you can do is implement a co-operational abort, say a while loop where the outside changes the expression or variable that is going to be tested.

        public void myThreadAction(...) {
        while(!threadStop) {
        ... go on
        }
        }

        The net result most often is the "abort" is not instantaneous, the while loop may (and should) call some blocking method (some input/output operation, or a Thread.Sleep). BTW: that is also the way you should do it on normal threads, a hard abort is to be avoided as one never knows in what state objects (such as locks, unmanaged resources) will be at the moment of the abort. :)

        Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

        Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

        D 1 Reply Last reply
        0
        • H Harvey Saayman

          Smart Thread Pool[^] supports cancelation of queued items.

          Harvey Saayman - South Africa Software Developer .Net, C#, SQL you.suck = (you.Occupation == jobTitles.Programmer && you.Passion != Programming) 1000100 1101111 1100101 1110011 100000 1110100 1101000 1101001 1110011 100000 1101101 1100101 1100001 1101110 100000 1101001 1101101 100000 1100001 100000 1100111 1100101 1100101 1101011 111111

          D Offline
          D Offline
          devvvy
          wrote on last edited by
          #4

          Excellent!

          dev

          H 1 Reply Last reply
          0
          • D devvvy

            Excellent!

            dev

            H Offline
            H Offline
            Harvey Saayman
            wrote on last edited by
            #5

            Glad to be of service :)

            My Band

            1 Reply Last reply
            0
            • L Luc Pattyn

              The standard ThreadPool holds threads for you to use; you never get full control over those threads, so there are a lot of managerial operations you can't perform on them, such as changing their priority, or aborting them. What you can do is implement a co-operational abort, say a while loop where the outside changes the expression or variable that is going to be tested.

              public void myThreadAction(...) {
              while(!threadStop) {
              ... go on
              }
              }

              The net result most often is the "abort" is not instantaneous, the while loop may (and should) call some blocking method (some input/output operation, or a Thread.Sleep). BTW: that is also the way you should do it on normal threads, a hard abort is to be avoided as one never knows in what state objects (such as locks, unmanaged resources) will be at the moment of the abort. :)

              Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

              Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

              D Offline
              D Offline
              devvvy
              wrote on last edited by
              #6

              Luc Pattyn wrote:

              a hard abort is to be avoided as one never knows in what state objects (such as locks, unmanaged resources) will be at the moment of the abort.

              Sorry any elaboration on this...? I can't see my calculation threads has any "State" to it... and my guess is for all practical reason I can throw an exception in the thread just to kill it. Am I missing something, Abort vs Interrupt?

              dev

              L 1 Reply Last reply
              0
              • D devvvy

                Luc Pattyn wrote:

                a hard abort is to be avoided as one never knows in what state objects (such as locks, unmanaged resources) will be at the moment of the abort.

                Sorry any elaboration on this...? I can't see my calculation threads has any "State" to it... and my guess is for all practical reason I can throw an exception in the thread just to kill it. Am I missing something, Abort vs Interrupt?

                dev

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

                you'll have state whenever some I/O is included, or something gets locked (e.g. a shared results queue), etc. Here is an excellent article on threading: http://www.albahari.com/threading/[^] My conclusion is: choose the co-operative way whenever you can. :)

                Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

                Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

                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