preventing thread from abort at specfic stage

i am creating a thread that will do some work and then enter those info in database.

use can abort that thread but i want to prevent that thread won't abort when it is inserting some thing in database, instead it will abort after that




Answer this question

preventing thread from abort at specfic stage

  • Kitek

    okey! let me give you guys a complete overview of what is going on.
    1- I am performing some operations which at first i was running on a delegate but my functions uses some com libraries such as WebBrowser control which requires thread to run in Stat so i created a thread and set its state to Stat and assigned it to a delegate and after starting thread i joined it.
    2- when user clicks on the Cancel button i am aborting that thread.
    3- what i want to prevent is that when it is doing database operations it won't abort.
    4- after completig those db operations it will abort.
    what are suggestions now


  • formhabit

    How does the user abort the thread - in the UI



  • sssmith03

    no! its not yet solved.

  • Nomad Guru

    well! thread is executing another class object which is performing a series of operations, as operations are of another class how can i get its status......


  • Bwlee-Java

    I would say use a delagated subroutine that you call periodically from the thread with the status of the thread. Or update a global variable (ugh.)



  • Mangix

    AFAIK, later versions of access allow stored procs.

    Really, you have all sorts of options, including just setting some boolean flags inside your threaded code. If it's possible for a thread to kill itself, I'd go with calling a method that sets a flag, and that flag causes the thread to kill itself when it leaves the current block of database code.



  • cdaniele

    // as there is a constraint in my application reqs. not to use stored procedures.

    I personally would argue that it should be a constraint that ALL DB access should be via stored procs. Can I ask why you have this constraint

    // can i set and change thread state so that when i will try to abort i will first check what is the thread state

    Well, one way or the other, the advice you've been given is your only real option, your constraints stop you from writing efficient code, so you need to set a flag somehow that you check before killing the thread.



  • Ettore

    no actually i am not using store procedures at all place so i have to got this way, as there is a constraint in my application reqs. not to use stored procedures.
    can i set and change thread state so that when i will try to abort i will first check what is the thread state


  • Carl Arnesten

    well! by clicking on a buttton.
    which will call thread.abort.


  • Liz____9

    Well, your UI thread is going to abort the worker thread, so it sounds like you need a way of checking first if a database operation is taking place, perhaps a mutex or something like that Surely a database operation is sent from your app to your data layer, and so if you wrote them as stored procs, once it starts, it's pretty much going to all happen even if your thread dies Because the command will have been recieved by the DB. You can certainly make your procs atomic in nature.

  • Larry Rap

    hi,

    Is your problem solved

    Thank you,
    Bhanu.



  • JClishe

    If the suggestions above don't help, can you describe your problem a bit more What have you tried Something not working Let us know if you need more help on this topic, or have decided to go in another direction.

  • Jyri Hujanen

    well! the reason is that my applicaiton is currently interacting with Sql but may be it will use Access as its database, and as to my knowledge you can't write Stored procedures in access.
    this is causing trouble.
    about setting variable i have check in threading that thread.BeginCriticalState and thread.EndCriticalState vice versa, then what is it


  • Monia Anand

    Why not disable/enabled the button at the appropriate times.  If the button is disabled then they cant execute the button click event code containing the thread.abort command

    Button1.enabled = false


  • preventing thread from abort at specfic stage