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
    Posts
    1

    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.
    Code:
            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";
                    backgroundWorker3.RunWorkerAsync();
                    fileTransferAlert.Close();
                }
            }
    This is the code for clicking Accept. It is in Form2, the file transfer request dialogue.
    Code:
            private void acceptButton_Click(object sender, EventArgs e)
            {
                
                FolderBrowserDialog fd = new FolderBrowserDialog();
                fd.ShowDialog();
                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
    Location
    Rocket City
    Posts
    220

    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
  •  





Click Here to Expand Forum to Full Width

Featured