System Is not Functioning Error. Windows XP, Arduino Uno R3, C# Listen SerialPort Can anyone help me with this issue.

We created an arduino project. We listen microswitch.
If switch click, Arduino send basic serial data.
And C# application read serial port.

This solution is working but after more times (3Hours, 5Hours,..) system stoped.
Error message is "a device attached to the system is not functioning"
Solution: Usb remove and retry plug system is going to running.

We are try putty.exe maybe problem C# project but don't working.

If microswitch click don't flash "TX" or "RX" led.

const int button = 3;

uint64_t bounceTime = 50;
uint64_t holdTime = 250;
uint64_t doubleTime = 500;

uint64_t lastReading = LOW;
uint64_t hold = 0;
uint64_t single = 0;

uint64_t onTime = 0;
uint64_t lastSwitchTime = 0;


void setup() {
 pinMode(button, INPUT_PULLUP);
 Serial.begin(9600);
}

void loop() {

 int reading = digitalRead(button);

 if (reading == HIGH &amp;&amp; lastReading == LOW) {
   onTime = millis();
 }

 if (reading == HIGH &amp;&amp; lastReading == HIGH) {
   if ((millis() - onTime) &gt; holdTime) {  
     hold = 1;
   }
 }

 if (reading == LOW &amp;&amp; lastReading == HIGH) {
   if (((millis() - onTime) &gt; bounceTime) &amp;&amp; hold != 1) {
     onRelease();
   }
   if (hold == 1) {
      delay(5000);
      reading = digitalRead(button);
      if(reading==LOW){
              Serial.println("B");
      }
     hold = 0;
   }  
 }
 lastReading = reading;

 if (single == 1 &amp;&amp; (millis() - lastSwitchTime) &gt; doubleTime) {
   single = 0;
 }

}

void onRelease() {
 if ((millis() - lastSwitchTime) &gt;= doubleTime) {
   single = 1;
   lastSwitchTime = millis();
   return;
 }  

 if ((millis() - lastSwitchTime) &lt; doubleTime) {
   single = 0;
   lastSwitchTime = millis();
 }  

}
I assume that by "USB" you mean "USB-to-serial adaptor".

Try running the same code without any serial communications, just have an LED do the equivalent of printing, and power it from a good power supply. If it runs for more than five hours, the problem is with the USB adaptor and/or your PC (Windows XP? Really?), and hence not relevant to this forum.

If the code crashes, then maybe you have a marginal board, or there is some other environmental factor that's giving you trouble. The code looks OK on first glance.