Board index » cppbuilder » Unable to suspend a thread from a Form->buttonclick event
Bhuvan Sharma
![]() CBuilder Developer |
Bhuvan Sharma
![]() CBuilder Developer |
Unable to suspend a thread from a Form->buttonclick event2004-02-12 07:36:42 PM cppbuilder63 I want to suspend a thread when the user clicks on Form Button, but it seems not to work. There is an Eaccess violation message when i try this command Nethread->Suspended=true. inside the Button click event. Please help cheers, Ronan |
Remy Lebeau (TeamB)
![]() CBuilder Developer |
2004-02-13 03:14:42 AM
Re:Unable to suspend a thread from a Form->buttonclick event
"Bhuvan Sharma" < XXXX@XXXXX.COM >wrote in message
QuoteThere is an Eaccess violation message when i try this command place. Gambit |
Bhuvan Sharma
![]() CBuilder Developer |
2004-02-16 08:38:27 PM
Re:Unable to suspend a thread from a Form->buttonclick eventQuoteAn AV occurs when you access invalid memory. Please show your actual thread based on global variable Issuspended value. ============================================= bool Issuspended; __fastcall AppThread::AppThread(bool CreateSuspended) : TThread(CreateSuspended) { Priority=tpLower; FreeOnTerminate=true; ADODataSet3 = new TADODataSet(NULL); ADOConnection3 = new TADOConnection(NULL); this->ADOConnection3->ConnectionString="Provider=MSDAORA.1;User ID=bhuvan;Data Source=CCDDEV;Persist Security Info=False"; this->ADOConnection3->Connected=true; this->ADODataSet3->Connection=this->ADOConnection3; } void __fastcall AppThread::Execute() { int i; SetName(); int track=Form1->TrackBar1->Position; CoInitialize(NULL); this->run_the_application(); //basically calls the other thread functions that do the database processing } void __fastcall TForm1::Button2Click(TObject *Sender) { //creates an application thread Newthread AppThread *Newthread= new AppThread(false); } void __fastcall TForm1::Button3Click(TObject *Sender) { if(Issuspended) { Issuspended=false; Newthread->Resume(); Form1->Button3->Caption="Pause"; } else { Issuspended=true; Newthread->Suspended=true; // or i culd have used Newthread->Suspend(); as well but it also returns the AV error Form1->Button3->Caption="Resume"; } } "Remy Lebeau (TeamB)" < XXXX@XXXXX.COM >wrote in message Quote
{smallsort} |
Remy Lebeau (TeamB)
![]() CBuilder Developer |
2004-02-17 06:42:29 AM
Re:Unable to suspend a thread from a Form->buttonclick event
"Bhuvan Sharma" < XXXX@XXXXX.COM >wrote in message
Quotevoid __fastcall TForm1::Button2Click(TObject *Sender) returns and you will no longer have any access to the thread. Quotevoid __fastcall TForm1::Button3Click(TObject *Sender) Gambit |
Bhuvan Sharma
![]() CBuilder Developer |
2004-02-17 11:36:13 PM
Re:Unable to suspend a thread from a Form->buttonclick event
Great, it works!!
thanks a ton "Remy Lebeau (TeamB)" < XXXX@XXXXX.COM >wrote in message Quote
|