简体   繁体   English

在“ C:\\ Program Files(x86)”之外运行时,为什么为“ x86”编译的WinForms应用程序不会在“ x64”计算机上退出?

[英]Why won't my WinForms app compiled for “x86” exit on an “x64” machine when running outside “C:\Program Files (x86)”?

We have a WinForms app that runs fine on x86, but has many third-party components that make win32 calls. 我们有一个WinForms应用程序,该应用程序可以在x86上正常运行,但是有许多进行win32调用的第三方组件。 To get the apps to run on x64, I now compile for the x86 platform. 为了使这些应用程序可以在x64上运行,我现在为x86平台进行编译。 Our habit has been to install our thick-client outside the system partition on servers, so we installed in "F:\\Program Files (x86)" yesterday on a Win2003 x64 server. 我们的习惯是在服务器的系统分区之外安装胖客户端,因此昨天我们在Win2003 x64服​​务器上安装了“ F:\\ Program Files(x86)”。 When run from that directory, the processes refused to exit. 从该目录运行时,进程拒绝退出。 I tried killing them in Task Manager, taskkill, and Process Explorer, but nothing short of rebooting the server would kill those processes. 我曾尝试在任务管理器,taskkill和进程资源管理器中将其杀死,但是重新启动服务器只会杀死那些进程。 When I uninstalled and reinstalled in C:\\Program Files (x86), the processes exit fine. 当我在C:\\ Program Files(x86)中卸载并重新安装后,进程退出正常。

Does the installation location really matter when running WinForms apps compiled for x86 on an x64 machine? 在x64机器上运行针对x86编译的WinForms应用程序时,安装位置真的重要吗?

From my experience I can tell that it is possible to run x86 binaries on x64 systems from pretty much any location (haven't tested if things still work if the binary is in system32, but I'm sure x86 programs can run from Program Files). 从我的经验来看,我可以在几乎任何位置在x64系统上运行x86二进制文件(如果二进制文件位于system32中,则尚未测试事情是否仍然有效,但是我确信x86程序可以从Program Files运行)。 I believe the Program Files / Program Files (x86) folders are just there to easily distinguish between native x64 apps and old x86 apps. 我相信Program Files / Program Files(x86)文件夹就可以轻松区分本机x64应用程序和旧的x86应用程序。 From your description what you're facing sounds much like a WoW64 compatibility issue, however if you've got dependencies on unmanaged code you'll probably want to verify first if that unmanaged code runs fine and then dig deeper in what's preventing your program from closing. 根据您的描述,您所面对的问题听起来很像WoW64兼容性问题,但是,如果您对非托管代码有依赖性,则可能需要先验证该非托管代码是否运行正常,然后再深入研究阻止程序运行的原因收盘。 Also, it would be helpful to know how are you trying to terminate the application in the first place, if it uses multiple threads or a single thread, the version of the .NET runtime that's targeting and the version that's installed on the server (incl. Service Pack). 另外,如果您首先尝试终止应用程序,使用多个线程还是使用单个线程,定位的.NET运行时版本以及服务器上安装的版本,这将很有帮助。 。 服务包)。

Here's a shot in the dark. 这是黑暗中的一枪。 Does your program attempt to read or load any data that is deployed with the application in the same directory or a sub directory? 您的程序是否尝试读取或加载与应用程序一起部署在同一目录或子目录中的任何数据? If so, there's the possibility that you are running into the following problem. 如果是这样,则可能会遇到以下问题。

It's possible that your application is using a value that is dependent on the processor architecture that it is running under to find the directory. 您的应用程序使用的值可能取决于在其下运行的处理器体系结构的目录。 Take for instance the environment variable ProgramFiles. 以环境变量ProgramFiles为例。 On a 64 bit machine, the ProgramFiles environment variable will actually point to the "Program Files (x86)" directory for a 32 bit application. 在64位计算机上,ProgramFiles环境变量实际上将指向32位应用程序的“ Program Files(x86)”目录。 So it's possible you're program is attempting to load data like the following and crashing 因此,您的程序可能正在尝试加载以下数据并崩溃

string root = Environment.GetVariable("ProgramFiles");
string file = Path.Combine(root, "MyAppName\DataDirectory\SomeDataFile.txt");
string data = File.ReadAllLines(file);  

The last line would fail because the path would resolve to 最后一行将失败,因为该路径将解析为

c:\\program files (x86)\\MyApplication\\DataDirectory\\SomeDataFile.txt c:\\ program files(x86)\\ MyApplication \\ DataDirectory \\ SomeDataFile.txt

But the application was deployed into Program Files. 但是该应用程序已部署到程序文件中。 So the real path would be 所以真正的路径是

c:\\program files\\MyApplication\\DataDirectory\\SomeDataFile.txt c:\\ program files \\ MyApplication \\ DataDirectory \\ SomeDataFile.txt

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM