How do I cancel?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • polygonVB
    New Member
    • Sep 2006
    • 15

    How do I cancel?

    Hi all. I'm a relatively young developer without any formal training so please pardon me if this question is stupid.

    I created a program to search a database. You enter a value into a textbox and it queries the database searching for this value. Then it displays the results in a listview.
    While the program is searching it's in a "Not Responding" state, and the program looks like it is frozen. Additionally you can not click any buttons like cancel.

    So how would I add a cancel feature to the search?

    Thanks much,
    Paul
  • sainin
    New Member
    • Sep 2006
    • 13

    #2
    Run the SEARCH functionality in a different "unjoined" thread. That will not bother the main thread, and you will be well able to click anywhere. Make sure to kill the SEARCH thread and any DB connections at appropriate call (CANCEL??).

    Hope that helps.

    Comment

    • Anil Prasad
      New Member
      • Sep 2006
      • 3

      #3
      Hi Paul,

      If the system goes into the frozen state it implies that the system going on infinit search so.. check the logic u applied.. and debug it propery using (attach break point and then F11)...

      this is not the big problem if it not get solved send me the the logic..
      i will try to solve it..


      Anil Prasad.
      Programmer
      ADCC Computing And Research NGP
      INDIA.

      Comment

      • Anil Prasad
        New Member
        • Sep 2006
        • 3

        #4
        Hi Paul,

        If the system goes into the frozen state it implies that the system going on infinit search so.. check the logic u applied.. and debug it propery using (attach break point and then F11)...

        this is not the big problem if it not get solved send me the the logic..
        i will try to solve it..


        Anil Prasad.
        Programmer
        ADCC Computing And Research NGP
        INDIA.

        --------------------------------------------------------------------------------

        Comment

        • polygonVB
          New Member
          • Sep 2006
          • 15

          #5
          Originally posted by sainin
          Run the SEARCH functionality in a different "unjoined" thread. That will not bother the main thread, and you will be well able to click anywhere. Make sure to kill the SEARCH thread and any DB connections at appropriate call (CANCEL??).

          Hope that helps.
          Yes I tried using a seperate thread and a backgroundworke r to accomplish this but I can't update the UI from the seperate thread. It returns cross thread errors. How do I update the controls on one thread from another thread? So after the search is done I can't update the user interface to let the user know about the results. Therefore making the search futile.


          Thanks the logic of the search function is fine. It runs and once it's done running the program responds normally.

          Tank you all
          Paul

          Comment

          • polygonVB
            New Member
            • Sep 2006
            • 15

            #6
            I'm re-writing this because the last one seemed confusing. I didn't see an edit function either.

            ------------------------------------------------------------------------------------------------------------
            Yes I tried using a seperate thread and a backgroundworke r to accomplish this but I can't update the UI from the seperate thread. It returns cross thread errors. So after the search is done I can't update the user interface to let the user know about the results. Therefore making the search futile.

            How do I update the controls on one thread from another thread?


            Thanks the logic of the search function is fine. It runs and once it's done running the program responds normally.

            Thank you all

            Comment

            • sainin
              New Member
              • Sep 2006
              • 13

              #7
              Polygon (Thats a nice name).

              OK. So here is the deal. Assume that your main form is FrmMain, and the search functionality is another class (say ClsSearch) OR just another function in the FrmMain class. Whichever way it is, the issue is how to get the results back when the search is complete (in a different thread), so that you can update some controls or write the search results back to the main form.

              The answer is (1) a mechanism which can notify the main thread that the search thread has completed its job; sort of inter-communication. (2) And further the main thread should have access to search thread's result (a DataSet, Huh??).

              1st task can be achived in a number of ways; a callback from the main thread, AND a watch on the search thread. Watching the search thread should be easy for you. Use a timer and keep checking for the search thread whether its alive or not.. (oSearchThread. IsAlive).. So as soon as the search threads goes off you are ready to paint the main form with the search results.

              2nd task is the search result. How will you pass it to the main form. Looks simple. Store the search results in a variable which is accessible to both the threads. Use the variable to populate you form once you have the confirmation from the first thread.

              Lemme know if I am confusing you....

              Best

              Comment

              • polygonVB
                New Member
                • Sep 2006
                • 15

                #8
                Originally posted by sainin
                Polygon (Thats a nice name).

                OK. So here is the deal. Assume that your main form is FrmMain, and the search functionality is another class (say ClsSearch) OR just another function in the FrmMain class. Whichever way it is, the issue is how to get the results back when the search is complete (in a different thread), so that you can update some controls or write the search results back to the main form.

                The answer is (1) a mechanism which can notify the main thread that the search thread has completed its job; sort of inter-communication. (2) And further the main thread should have access to search thread's result (a DataSet, Huh??).

                1st task can be achived in a number of ways; a callback from the main thread, AND a watch on the search thread. Watching the search thread should be easy for you. Use a timer and keep checking for the search thread whether its alive or not.. (oSearchThread. IsAlive).. So as soon as the search threads goes off you are ready to paint the main form with the search results.

                2nd task is the search result. How will you pass it to the main form. Looks simple. Store the search results in a variable which is accessible to both the threads. Use the variable to populate you form once you have the confirmation from the first thread.

                Lemme know if I am confusing you....

                Best
                Thanks I'll try this.

                I tried this without waiting for the search thread to finish, so the variable that I passed between the threads was = to Nothing. Because of the blank variable I thought that you weren't able to pass variables between the two threads, but now I'm thinking that the search thread hadn't gotten to the part where it added something to the variable when the main thread looked at my variable.
                I think I'm on to something now, thanks alot!

                Paul

                Comment

                • polygonVB
                  New Member
                  • Sep 2006
                  • 15

                  #9
                  Thanks sainin!

                  That was exactly what I was looking for. I got my cancel button working and everything is right in the world :-).

                  Thank you to everyone else as well!

                  Paul

                  Comment

                  Working...