views:

182

answers:

0

I'm developing a C#/WPF application using Visual Studio. This app uses a com port, then releases it upon exit. I'm using the debugger to run and stop this application often. Sometimes, I get an exception when starting up a debug session saying that the com port is already in use.

The code always closes the open com port on exit, so I ran portmon to see who was holding on to the port. It turns out that in "normal" cases, the port is grabbed, used, and closed by my application (Process KaleidoscopeApp in portmon). In the case where the port is not released, the port is being used by process "devenv", which is Visual Studio itself.

Why is devenv the owner of the com port in these cases? When I close the app, why does it continue to hold it? Only when I close Visual Studio is the port released. It is strange behavior especially since the debugger has specifically halted within Visual Studio.

Here is a capture from portmon showing access to the com port. You can see a typical session begins with IRP_MJ_CREATE and ends with IRP_MJ_CLOSE. This is always the case with KaleidoscopeApp. You can see the last bit is run by devenv. Yet each launch is always in the VS debugger.


357 0.11112275 KaleidoscopeApp IRP_MJ_CREATE Serial4 SUCCESS Options: Open
358 0.00000305 KaleidoscopeApp IOCTL_SERIAL_GET_PROPERTIES Serial4 SUCCESS
...

406 0.02997366 KaleidoscopeApp IRP_MJ_CLEANUP Serial4 SUCCESS
407 0.03390231 KaleidoscopeApp IRP_MJ_CLOSE Serial4 SUCCESS
408 0.11443431 KaleidoscopeApp IRP_MJ_CREATE Serial4 SUCCESS Options: Open
409 0.00000727 KaleidoscopeApp IOCTL_SERIAL_GET_PROPERTIES Serial4 SUCCESS
...

457 0.02995160 KaleidoscopeApp IRP_MJ_CLEANUP Serial4 SUCCESS
458 0.03389956 KaleidoscopeApp IRP_MJ_CLOSE Serial4 SUCCESS
459 0.11307261 devenv.exe IRP_MJ_CREATE Serial4 SUCCESS Options: Open
460 0.00000185 devenv.exe IOCTL_SERIAL_GET_PROPERTIES Serial4 SUCCESS
...

501 35.55274341 devenv.exe IOCTL_SERIAL_WAIT_ON_MASK Serial4 CANCELLED


Any insight would be appreciated!