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. Thread, User closes app while thread running

Thread, User closes app while thread running

Scheduled Pinned Locked Moved C#
databasehelpvisual-studioquestion
4 Posts 4 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.
  • E Offline
    E Offline
    ewaldw
    wrote on last edited by
    #1

    Hi All. Can someone please help. I am using vs 2003 and SQL 2000. I have to insert about 50000 records into sql. I have tried to use a tread to do this, but when the user say closes the app while the second thread is still running, the app is closed, but the thread is still running and still inserting rows into the database. The code that i used to create a thread is as follows: Thread t1 = new Thread(new ThreadStart(ThreadLoadingData)); t1.Name = "ThreadLoadingData"; t1.Start(); I used the tread in the same class. In ThreadLoadingData i go to different classes for inserting the data. Thera are 5 tables that i must insert into, each one i use a different class. Now i also need to display a progress bar for this, how do i go about solving this problem Thanks

    F A S 3 Replies Last reply
    0
    • E ewaldw

      Hi All. Can someone please help. I am using vs 2003 and SQL 2000. I have to insert about 50000 records into sql. I have tried to use a tread to do this, but when the user say closes the app while the second thread is still running, the app is closed, but the thread is still running and still inserting rows into the database. The code that i used to create a thread is as follows: Thread t1 = new Thread(new ThreadStart(ThreadLoadingData)); t1.Name = "ThreadLoadingData"; t1.Start(); I used the tread in the same class. In ThreadLoadingData i go to different classes for inserting the data. Thera are 5 tables that i must insert into, each one i use a different class. Now i also need to display a progress bar for this, how do i go about solving this problem Thanks

      F Offline
      F Offline
      Filip van der Meeren
      wrote on last edited by
      #2

      Well to close the thread : t1.Abort (); This causes a ThreadAbortException you just catch it in the method of the thread (in this case "ThreadLoadingData"). When the exception is caught you just stop uploading. For the rest, the progress stuff, there is a special class in .net that handles this, I don't have the time to look, but I suggest you take a look online for this in Google or some other searchengine.

      Don't you also love the code?

      1 Reply Last reply
      0
      • E ewaldw

        Hi All. Can someone please help. I am using vs 2003 and SQL 2000. I have to insert about 50000 records into sql. I have tried to use a tread to do this, but when the user say closes the app while the second thread is still running, the app is closed, but the thread is still running and still inserting rows into the database. The code that i used to create a thread is as follows: Thread t1 = new Thread(new ThreadStart(ThreadLoadingData)); t1.Name = "ThreadLoadingData"; t1.Start(); I used the tread in the same class. In ThreadLoadingData i go to different classes for inserting the data. Thera are 5 tables that i must insert into, each one i use a different class. Now i also need to display a progress bar for this, how do i go about solving this problem Thanks

        A Offline
        A Offline
        Ahmed Ismail Mohamed
        wrote on last edited by
        #3

        I think that there is a usefull articale in the threading section its title is: "Wait for threads in a ThreadPool object to complete" By gtamir. here is its URL: http://www.codeproject.com/csharp/waitforthreads.asp[^] I wish you find what do you want exactlu in it. Regards:) Ahmed Ismail

        1 Reply Last reply
        0
        • E ewaldw

          Hi All. Can someone please help. I am using vs 2003 and SQL 2000. I have to insert about 50000 records into sql. I have tried to use a tread to do this, but when the user say closes the app while the second thread is still running, the app is closed, but the thread is still running and still inserting rows into the database. The code that i used to create a thread is as follows: Thread t1 = new Thread(new ThreadStart(ThreadLoadingData)); t1.Name = "ThreadLoadingData"; t1.Start(); I used the tread in the same class. In ThreadLoadingData i go to different classes for inserting the data. Thera are 5 tables that i must insert into, each one i use a different class. Now i also need to display a progress bar for this, how do i go about solving this problem Thanks

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

          If you want to kill the thread when the user closes the app, simply set System.Threading.Thread.IsBackground[^] to true.

          Regards Senthil _____________________________ My Blog | My Articles | WinMacro

          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