May 30th, 2013, 01:55 AM
Using FolderBrowserDialog, experiencing crashing when trying to ShowDialog()
Specifically, I'm experiencing crashing if I use the ShowDialog method in a secondary form. I'm working on adding file transfer functionalities to a really basic asynchronous chat program. What I'm trying to do is, when the user receives a file transfer request, a dialogue pops up asking whether to accept or deny the transfer. Upon clicking accept, I want the user to be able to browse to a folder where that file gets saved.
Here's my code.
This is in the main form, Form1 and runs when a request for file transfer is received.
This is the code for clicking Accept. It is in Form2, the file transfer request dialogue.
private void backgroundWorker2_DoWork(object sender, DoWorkEventArgs e)
Form2 fileTransferAlert = new Form2();
string result = fileTransferAlert.ShowDialog().ToString();
if (result == DialogResult.No.ToString())
sendStatus = "dec";
fileTransferAlert.Close(); // close the connection setup form
else if (result == DialogResult.Yes.ToString())
sendStatus = "acc";
When I click accept, the program simply hangs until I click around the form, and only then will windows tell me it's stopped working.
private void acceptButton_Click(object sender, EventArgs e)
FolderBrowserDialog fd = new FolderBrowserDialog();
if (fd.ShowDialog() == DialogResult.OK)
fileReceive.receivedPath = fd.SelectedPath;
this.DialogResult = System.Windows.Forms.DialogResult.Yes;
By the way, the sticky in all caps told me to tell you all that I'm using .NET version 4.0.
May 30th, 2013, 12:48 PM
Re: Using FolderBrowserDialog, experiencing crashing when trying to ShowDialog()
You are using fd.ShowDialog() twice. Try eliminating the first one.
Tags for this Thread
Click Here to Expand Forum to Full Width
This is a CodeGuru survey question.