CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    May 2013

    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.
            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";
    This is the code for clicking Accept. It is in Form2, the file transfer request dialogue.
            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;
    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.

    By the way, the sticky in all caps told me to tell you all that I'm using .NET version 4.0.

  2. #2
    Join Date
    Oct 2004
    Rocket City

    Re: Using FolderBrowserDialog, experiencing crashing when trying to ShowDialog()

    You are using fd.ShowDialog() twice. Try eliminating the first one.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)