This is running in a background worker The issue appears to be with the registry check if the key FS is missing it errors out. I'm doing this check just in case someone deletes it even though the installer adds the values. Also wondering why message boxes aren't working
//I DONT EVEN GET TO THIS MESSAGE BOX BEFORE THE ERROR
//BUT THE CATCH IS TRIGGERED FROM THE TRY BLOCK
MessageBox.Show("Entered Version Check");
try
{
//DONT GET TO SEE THIS MESSAGE BOX
MessageBox.Show("Entered try");
DirectoryInfo Temp = new DirectoryInfo(Path.GetTempPath());
RegistryKey rk = Registry.LocalMachine.OpenSubKey("Software\\My Application Here");
string val;
if (rk != null)
{
val = rk.GetValue("FS").ToString();
if (val == null)
{
MessageBox.Show("It appears that you do not have a File Server IP address configured" + Environm开发者_Go百科ent.NewLine + "Please login to the admin tools and set it", "No File Server Set", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
}
val = rk.GetValue("FS").ToString();
That's going to bomb if GetValue() returns null. First check for null before you try ToString(). And add a check in the BGW's RunWorkerCompleted event handler so you can verify e.Error. And don't display message boxes in a worker thread, odds are good that they'll disappear behind the window of another app, including your own.
The most common issue like this I've seen is related to the 64bit registry redirection. Are you running on a 64bit OS, with your application compiled as 32bit? If so, the registry calls will be redirected.
Either look under the HKLM\SOFTWARE\Wow6432Node
key for your key, or compile your application as 64bit.
精彩评论