The original Arduino CDC code used a delay to avoid some issue at cost of blocking all other code. As a result, this caused a big issue if you want to know if computer connects Arduino while you do fast/complex tasks. 10 milliseconds delay will cause a lot of issues.
You can see the code in loop can run 100 times per second.
There was commit to fix the issue (although not merged)
This makes state polling non-blocking to fix https://github.com/webusb/arduino/issues/50
The original Arduino CDC code used a delay to avoid some issue at cost of blocking all other code. As a result, this caused a big issue if you want to know if computer connects Arduino while you do fast/complex tasks. 10 milliseconds delay will cause a lot of issues.
You can see the code in loop can run 100 times per second.
There was commit to fix the issue (although not merged)
"Fixed slowdown with repeated CDC bool operator test" https://github.com/arduino/ArduinoCore-avr/commit/53944cf44418c8c19906794ef904ae8353a4cc2d
There is only one delay when computer connects.
I tried to improve that commit and remove all delay. Now the code is no longer blocking.
And it will not interfere with other code.