C# threading a FolderBrowserDialog
Posted
by
Marthin
on Stack Overflow
See other posts from Stack Overflow
or by Marthin
Published on 2011-01-16T16:15:46Z
Indexed on
2011/01/16
16:53 UTC
Read the original article
Hit count: 307
Hi,
Im trying to use the FolderBrowserDialog to select a folder in C#. At first I got a Thread exception, so I googled what was wrong and fixed that but now im stuck at a nother problem. I whant to know when a folder has been selected.
This is what i'v got right now.
private void btnWorkingFolder_Click(object sender, EventArgs e)
{
var t = new Thread(SelectFolder);
t.IsBackground = true;
t.SetApartmentState(ApartmentState.STA);
t.Start();
}
private void SelectFolder()
{
FolderBrowserDialog dialog = new FolderBrowserDialog();
if (dialog.ShowDialog() == DialogResult.OK)
{
txtWorkFolder.Text = dialog.SelectedPath;
}
}
}
The problem here is that i cant Set the Text for txtWorkingFolder since im not in the same thread. I dont want to change the thread for txtWorkingFolder, so my question is this, how do I change it's value from the new thread once the DialogResult.OK has been set?
Thx for any help! /Marthin
© Stack Overflow or respective owner