简体   繁体   中英

How to check another instance of application is running using the same resource

I want to find another instance of application is running for the same resource already. My application supports multiple instances. I would like to restrict one instance per resource.

Application executable name is COMTest.exe Assembly Title is COMPortTest. Task Manager shows the assembly title. Application title can be COMPort1, COMPort2...COMPortX. Task Manager also shows the application title.

Let say if an instance is running for COM1 port and user launches another instance and select the same COM1 port, i should post error message.

i would like to check the application title of the running application. How can i do this.

Thanks

This is one of those cases, where the most reliable way could be to try and just handle the exceptions.

The COM ports being in use already is entirely exogenous to your application . And even if you could communicate this between instances of your program, what if some other program is using those ports?

You can not avoid it. You can not sensibly test for it. It is not fatal. It is clearly exogenous. So whatever Exceptions are thrown should be handled by your COM access code. You will propably use some form of loop or function call, and this handling can be done inside that loop or function.

One alternative could be to have the actually testing be done by a daemon. You can start it via TaskSheduler, you get a GUI for each user and the parties just communicate via any IPC approach you like . Of course you would still have to deal with somebody else's program using those ports, so you wouldn't really gain anything.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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