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