这是在后台工作中运行 问题似乎与注册表检查密钥FS是否错过了它的错误。 我正在做这个检查,以防万一有人删除它,即使安装程序添加了值。 也想知道为什么消息框不工作C#注册表问题
//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" + Environment.NewLine + "Please login to the admin tools and set it", "No File Server Set", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
}
根据您的意见错误发生在第一行代码之前。如果您不向我们显示代码,那么很难确定导致错误的原因。 –
Windows窗体应用程序?你甚至可以使用后台线程的GUI?如果你在前台做它,它会起作用吗? –
@JohnSaunders是的,MessageBox.Show()调用可以从后台线程进行,但它们不会对主UI线程模态化。后台线程尝试直接访问UI线程上的控件是很危险的。 –