I there a good reason for the convoluted closing routine? Is this the actual code that causes problems? I could see you having some issues with the close hanging if you were using a sensor change handler, but you're not, so...
I did the closing this way to give the phidgets enough time to close (i read in the forum something about using Application.DoEvents() when having problems with closing, but unity3D does not support Application.DoEvents() and coroutines are advised to be used).
But i tried a very straightforward:
ifKit.close();
ifKit = null;
Application.DoEvents() is only needed for some fairly specific cases. It has to do with Phidgets events. Since the events are coming in on a seperate thread, they will invoke their event handlers in the context of their owning object if invokeRequired is true. Because close is called in the GUI example in the same context as the invoked events (ie sensor change event), there may be a pending sensor change event while the formClosed event is running. Therefore if we call close, we get a deadlock -> close will not return until the sensorChange event returns from its invoke, but the sensorChange event won't get invoked until after formClosed returns.
So, we de-register the event, call Application.DoEvents() to make the sensorChange event run right now, then call close.
I doubt this is the problem you're having, as you aren't using the sensorChange event, and the attach event is not likely causing issues - unless you happen to attach the Phidget right as you are closing the program.
If you are using sensorChange events - which really is the only thing I can think of that would cause your issue, then you need to look at what you event is doing, and whether it is being invoked or not.
I've tried installing the latest version of unity3d with the latest phidget-drivers today and still no luck.
Strange thing is that when running in IDE-mode (run inside the development interface) closing is not a problem. Only when running the published .exe file.
Also when i just create the 'interfaceKit' object and attach an event-handler (attachEventHandler for example) and then don't call the open method, everything closes fine.
What happens if you don't call close? It may not be necessary in your case - you really only need to worry about it if you want to close and then open multiple times in one program run. The Phidgets will be released when the program exits. Also, close is called and the handle is cleaned up in the class finalize method which gets called from garbage collection.
When running the simpified version (just connecting to the phidget) in the unity3D IDE, it closes fine and connects fine the following times.
Just when i publish the unity3D and then run it, i can't close it without hanging.