Hi,
I programming a windows forms application with visualC++ 2008 Express Edition. I have a button event that triggers a folderBrowseDialog component to open. When the user chooses a folder, the dialog closes and the application hangs indefinitely.
Heres the code
When I comment out temp->Join(), the app does not hang but if I do that, the folderBrowseDialog can be pushed behind the main application, which is what I dont want. I want the folderBrowseDialog to be in front until the user chooses a folder or exits the dialog. How can I stop the application hang? Thanks
I programming a windows forms application with visualC++ 2008 Express Edition. I have a button event that triggers a folderBrowseDialog component to open. When the user chooses a folder, the dialog closes and the application hangs indefinitely.
Heres the code
Code:
button2_Click(System::Object^ sender, System::EventArgs^ e) {
System::Threading::Thread^ temp = gcnew System::Threading::Thread( gcnew System::Threading::ThreadStart(this, &FormApp::Form1::folderDialog));
temp->SetApartmentState(System::Threading::ApartmentState::STA);
temp->Start();
temp->Join();
}
private: void folderDialog(){
////create and show a directory dialog box
folderBrowserDialog1 = gcnew FolderBrowserDialog();
//folderBrowser->RootFolder = Environment::SpecialFolder::MyComputer;
//// save the current directory
String^ currentDirectory = System::IO::Directory::GetCurrentDirectory();
////show the dialog
System::Windows::Forms::DialogResult result = folderBrowserDialog1->ShowDialog();
if(result == System::Windows::Forms::DialogResult::OK){
folderName = folderBrowserDialog1->SelectedPath;
//enable the preview button
button3->Enabled = true;
}
}
When I comment out temp->Join(), the app does not hang but if I do that, the folderBrowseDialog can be pushed behind the main application, which is what I dont want. I want the folderBrowseDialog to be in front until the user chooses a folder or exits the dialog. How can I stop the application hang? Thanks
Last edited: