Quick question
I'm introducing myself to threads (in C# but I guess principles are principles)
Is there a way to tell whether there any user spawned threads running?
App:
Doing database insertion.
so you can insert records from a file. (call them dacs)
each file can have thousands of dacs to insert and the ui allows you to specify many files at once
i didn't want to have the ui freeze up on the user while the records are being inserted (it can take a while) so i had each file spawn a new thread
the thread will open the file, get the records and insert them
however i didn't want the user to be able todo something silly during this process (like click insert on the same files again) so i disabled the buttons while the insertion is taking place
i need a way to tell when all the insertions are done so i can reactivate the buttons
currently the way i have this implemented is every time i spawn a new thread, i name that thread the same as the filename (filenames are unique)
i then add that filename to an arraylist
when all the threads are created, i spawn a new thread (mon) that monitors the size of the arraylist
the last thing that any thread does is remove the filename from the arraylist
when the arraylist is empty (all threads have stopped running) , mon reactivates the buttons and shows the status of the insertions etc
is there an easier way to tell when the threads have stopped running? (well i guess technically i don't have to add/remove the filename, but add/remove from position 0 should be sufficient but you get my point)
I'm introducing myself to threads (in C# but I guess principles are principles)
Is there a way to tell whether there any user spawned threads running?
App:
Doing database insertion.
so you can insert records from a file. (call them dacs)
each file can have thousands of dacs to insert and the ui allows you to specify many files at once
i didn't want to have the ui freeze up on the user while the records are being inserted (it can take a while) so i had each file spawn a new thread
the thread will open the file, get the records and insert them
however i didn't want the user to be able todo something silly during this process (like click insert on the same files again) so i disabled the buttons while the insertion is taking place
i need a way to tell when all the insertions are done so i can reactivate the buttons
currently the way i have this implemented is every time i spawn a new thread, i name that thread the same as the filename (filenames are unique)
i then add that filename to an arraylist
when all the threads are created, i spawn a new thread (mon) that monitors the size of the arraylist
the last thing that any thread does is remove the filename from the arraylist
when the arraylist is empty (all threads have stopped running) , mon reactivates the buttons and shows the status of the insertions etc
is there an easier way to tell when the threads have stopped running? (well i guess technically i don't have to add/remove the filename, but add/remove from position 0 should be sufficient but you get my point)
