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.