且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

DoubleClick文件和C#混淆

更新时间:2023-02-09 16:30:40

否,您不能防止双击".点击是由用户完成的;这是您无法控制的.
您可以轻松地做一件简单的事情:更改可执行文件的扩展名.您使用System.Diagnostics.Process.Start运行该应用程序.对于此调用,扩展名根本不重要,但是Shell不会双击该文件将其识别为可执行文件.

但是为什么呢?
没有必要运行流程.一站式完成.使您第二个可执行文件成为库,并在调用过程中运行所需的某些方法.您可以在主线程中执行操作,也可以为其创建单独的线程.您甚至可以在单独的应用程序域中运行它.这完全取决于您的目的.无论如何,创建单独的线程几乎没有任何东西,而仅在一个进程中是无法实现的.

有关更高级的用法,请阅读以下内容:创建使用Reloadable的WPF应用程序插件... [ ^ ].

—SA
No, you can not "prevent double click". The click is done by the user; this is beyond your control.
You can easily do one simple thing: change extension of the executable file. You run the application using System.Diagnostics.Process.Start. For this call, extension does not matter at all, but the Shell won''t recognize the file as executable on double click.

But why?
There is not point of running to processes. Make it all in one process. Make you second executable a library and run some method you want in your calling process. You can do in main thread or create a separate thread for it. You can even run it in a separate Application Domain. It all depends on you purpose. Anyway, there is practically nothing in creating of a separate thread which you can not achieve in just one process.

For more advanced uses, read this: Create WPF Application that uses Reloadable Plugins...[^].

—SA


-SA建议您完善解决方案.尝试第二个exe到dll库.
如果仍要保留2nd.exe,则可以将参数从1st.exe传递到2nd.exe,然后从2nd.exe检查该参数.如果它与特定的arg值匹配,则继续进行进一步处理,否则终止它.当用户双击2nd.exe时,它将不传递任何参数,或者如果传递则与您传递的参数匹配.
要了解命令行参数,请参阅本文:
C#/.NET命令行参数解析器 [命令行参数 [
-SA Advised you to perfect solution. Try your second exe to dll library.
If you still want to keep your 2nd.exe you can pass an argument from 1st.exe to 2nd.exe, and check that argument from 2nd.exe. If it match that specific arg value then continue farther processing else terminate it.When user double click on 2nd.exe it will not pass any argument or if passed then it is matched to your passed argument.
To know about command line argument see this article:
C#/.NET Command Line Arguments Parser[^]
or
Command Line Arguments[^]