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. Stopping/canceling a running database query

Stopping/canceling a running database query

Scheduled Pinned Locked Moved C#
databasecsharpsaleshelpquestion
3 Posts 2 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.
  • R Offline
    R Offline
    Robert Rohde
    wrote on last edited by
    #1

    Hi folks, what would be a good way to make a database query cancelable? Purpose is that the user should abort the function if it takes too long. I've already stuffed the whole database access logic into a separate thread. When the user clicks the abort button then the Thread.Abort function is called. Problem 1: The thread ignores the Abort call until the query is completely processed. Problem 2: Somehow I cannot fire a second query while the first hasn't finished (e.g. User quickly clicks Search->Cancel->Search). I'm not sure why - it might be the underlying Access database (please don't mock me for that - the db is set by the customer). I'm working with .Net 1.1. Any ideas?

    J 1 Reply Last reply
    0
    • R Robert Rohde

      Hi folks, what would be a good way to make a database query cancelable? Purpose is that the user should abort the function if it takes too long. I've already stuffed the whole database access logic into a separate thread. When the user clicks the abort button then the Thread.Abort function is called. Problem 1: The thread ignores the Abort call until the query is completely processed. Problem 2: Somehow I cannot fire a second query while the first hasn't finished (e.g. User quickly clicks Search->Cancel->Search). I'm not sure why - it might be the underlying Access database (please don't mock me for that - the db is set by the customer). I'm working with .Net 1.1. Any ideas?

      J Offline
      J Offline
      J4amieC
      wrote on last edited by
      #2

      Within your data access class, store a boolean variable such as Cancelling. Now, read your data in chunks using something like a DataReader, except after reading each chunk of data check whether the Cancelling flag has been set to true. If it has, close your data reader and connection and return from the method as quickly as possible. You can now do exactly as you were, starting that data access on its own thread. When you want to cancel, set the flag in your data access class to true and Thread.Join the data access thread before firing off a new request.In this way, no Thread.Abort will be required.

      R 1 Reply Last reply
      0
      • J J4amieC

        Within your data access class, store a boolean variable such as Cancelling. Now, read your data in chunks using something like a DataReader, except after reading each chunk of data check whether the Cancelling flag has been set to true. If it has, close your data reader and connection and return from the method as quickly as possible. You can now do exactly as you were, starting that data access on its own thread. When you want to cancel, set the flag in your data access class to true and Thread.Join the data access thread before firing off a new request.In this way, no Thread.Abort will be required.

        R Offline
        R Offline
        Robert Rohde
        wrote on last edited by
        #3

        A DataReader won't help me in this situation because the request normally returns only one row. Thus the first DaraReader.Read call will block. Any other ideas?

        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