Dobry den,
potreboval bych poradit delam program jehoz jedna funkcnost je hledani souboru napsal jsem si na to vlastni tridu protoze chci hledani spoustet na extra vlaknu:
class FileSearch
{
private string _directoryPath;
private string _searchPattern;
private TextBox _outputTextbox;
public FileSearch(string directoryPath, string searchPattern, TextBox outputTextbox)
{
this._directoryPath = directoryPath;
this._searchPattern = searchPattern;
this._outputTextbox = outputTextbox;
}
public void StartSearch()
{
try
{
DirectoryInfo directoryInfo = new DirectoryInfo(_directoryPath);
DirectoryInfo[] directories = directoryInfo.GetDirectories();
foreach (DirectoryInfo dir in directories)
{
FileSearch fs = new FileSearch(dir.FullName, _searchPattern, _outputTextbox);
fs.StartSearch();
}
FileInfo[] files = directoryInfo.GetFiles(_searchPattern);
foreach (FileInfo file in files)
{
_outputTextbox.Text += String.Format("{0}\r\n", file.FullName);
}
}
catch (Exception e)
{
System.Windows.Forms.MessageBox.Show(e.Message);
}
}
}
spoustim to takto:
FileSearch fs = new FileSearch(_folderPath, _mask, txt_result);
Thread t = new Thread(fs.StartSearch);
t.Start();
ale kdyz to spustim tak dostanu chybu:
The calling thread cannot access the object because different thread owns it.
Nevite jak to vyresit?
Dekuji za odpoved