Click here to Skip to main content
15,910,009 members
Home / Discussions / C#
   

C#

 
AnswerRe: Returning date time as null Pin
souidi abderrahman3-Dec-09 5:58
souidi abderrahman3-Dec-09 5:58 
AnswerRe: Returning date time as null Pin
PIEBALDconsult3-Dec-09 8:23
mvePIEBALDconsult3-Dec-09 8:23 
GeneralRe: Returning date time as null Pin
Luc Pattyn3-Dec-09 9:02
sitebuilderLuc Pattyn3-Dec-09 9:02 
QuestionC# application to sort SQL database data and output to CSV file Pin
totally_stumped3-Dec-09 4:38
totally_stumped3-Dec-09 4:38 
AnswerRe: C# application to sort SQL database data and output to CSV file Pin
dan!sh 3-Dec-09 4:55
professional dan!sh 3-Dec-09 4:55 
AnswerRe: C# application to sort SQL database data and output to CSV file Pin
Shorgov3-Dec-09 5:13
Shorgov3-Dec-09 5:13 
AnswerRe: C# application to sort SQL database data and output to CSV file Pin
PIEBALDconsult3-Dec-09 5:15
mvePIEBALDconsult3-Dec-09 5:15 
QuestionKilling threads on form closing... Pin
Jacob Dixon3-Dec-09 2:59
Jacob Dixon3-Dec-09 2:59 
I am kind of digging into this threading business and having some trouble. I created the threads (one for prefilling a bunch of information from a SQL database, and another one for inserting files into the database if the user chooses to do so). So the first on happens on load and the other one could happen at any time by either clicking the Attach button, or by dragging and dropping a file from the desktop to the listview.

Problem is when I spawn the thread and the user closes the form before the file is uploaded (the form is a child form and is not the parent main form), it gives an error about the control cannot be invoked when the handle is not created. OK, I understand that it has disposed of the forms controls and thats why it has done this... but how do I make sure these threads are stopped before disposing of all the components on the form?


Here is the method I used to pass the information about the file. So I call this method on the main thread and this methods sets the global variables (so the new thread can access them and have the information to insert into the database), show the progressbar, and then spawn the thread. As you can see the thread is not a declared globally so the dispose method cannot access it directly correct?
private void SaveFile(string fileName, string safeFileName, bool fileMR)
{
    this.fileName       = fileName;
    this.safeFileName   = safeFileName;
    this.fileMR         = fileMR;

    if (fileMR)
        picProgressFilesMR.Visible = true;
    else
        picProgressFiles.Visible = true;

    Thread fileThread = new Thread(new ThreadStart(saveFiles));
    fileThread.IsBackground = true;
    fileThread.Start();
}

AnswerRe: Killing threads on form closing... Pin
Luc Pattyn3-Dec-09 3:12
sitebuilderLuc Pattyn3-Dec-09 3:12 
GeneralRe: Killing threads on form closing... Pin
Jacob Dixon3-Dec-09 3:19
Jacob Dixon3-Dec-09 3:19 
GeneralRe: Killing threads on form closing... Pin
Luc Pattyn3-Dec-09 3:28
sitebuilderLuc Pattyn3-Dec-09 3:28 
GeneralRe: Killing threads on form closing... Pin
Jacob Dixon3-Dec-09 3:36
Jacob Dixon3-Dec-09 3:36 
GeneralRe: Killing threads on form closing... Pin
Luc Pattyn3-Dec-09 3:58
sitebuilderLuc Pattyn3-Dec-09 3:58 
GeneralRe: Killing threads on form closing... Pin
ely_bob3-Dec-09 8:03
professionalely_bob3-Dec-09 8:03 
AnswerRe: Killing threads on form closing... Pin
Nicholas Butler3-Dec-09 3:17
sitebuilderNicholas Butler3-Dec-09 3:17 
GeneralRe: Killing threads on form closing... Pin
Jacob Dixon3-Dec-09 3:21
Jacob Dixon3-Dec-09 3:21 
GeneralRe: Killing threads on form closing... Pin
Nicholas Butler3-Dec-09 3:36
sitebuilderNicholas Butler3-Dec-09 3:36 
AnswerRe: Killing threads on form closing... Pin
Ian Shlasko3-Dec-09 3:20
Ian Shlasko3-Dec-09 3:20 
GeneralRe: Killing threads on form closing... Pin
Jacob Dixon3-Dec-09 3:32
Jacob Dixon3-Dec-09 3:32 
GeneralRe: Killing threads on form closing... Pin
Ian Shlasko3-Dec-09 4:04
Ian Shlasko3-Dec-09 4:04 
GeneralRe: Killing threads on form closing... Pin
Jacob Dixon3-Dec-09 3:43
Jacob Dixon3-Dec-09 3:43 
GeneralRe: Killing threads on form closing... Pin
Luc Pattyn3-Dec-09 5:38
sitebuilderLuc Pattyn3-Dec-09 5:38 
AnswerRe: Killing threads on form closing... Pin
PIEBALDconsult3-Dec-09 4:49
mvePIEBALDconsult3-Dec-09 4:49 
QuestionRedundant function? Pin
Spoon Of Doom3-Dec-09 2:51
Spoon Of Doom3-Dec-09 2:51 
AnswerRe: Redundant function? Pin
David Skelly3-Dec-09 3:05
David Skelly3-Dec-09 3:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.