Second Thread Holding Up Entire Program in C# Windows Form Application
Posted
by
Brandon
on Stack Overflow
See other posts from Stack Overflow
or by Brandon
Published on 2012-04-05T16:52:48Z
Indexed on
2012/04/05
17:31 UTC
Read the original article
Hit count: 298
In my windows form application, I'm trying to test the user's ability to access a remote machine's shared folder. The way I'm doing this (and I'm sure that there are better ways...but I don't know of them) is to check for the existence of a specific directory on the remote machine (I'm doing this because of firewall/other security restrictions that I'm confronted with in my organization). If the user has rights to access the shared folder, then it returns in no time at all, but if they don't, it hangs forever. To solve this, I threw the check into another thread and wait only 1000 milliseconds before determining that the share can't be hit by the user. However, when I do this, it still hangs as if it was never run in the same thread.
What is making it hang and how do I fix it? I would think that the fact that it is in a separate thread would allow me to just let the thread finish on it's own in the background.
Here is my code:
bool canHitInstallPath = false;
Thread thread = new Thread(new ThreadStart(() =>
{
canHitInstallPath = Directory.Exists(compInfo.InstallPath);
}));
thread.Start();
thread.Join(1000);
if (canHitInstallPath == false)
{
throw new Exception("Cannot hit folder: " + compInfo.InstallPath);
}
© Stack Overflow or respective owner