Hello
I want to set the system time in my application. When I run the code below, it takes up to 15 secs before the touch screen becomes full responsive. It was initially having an effect on my serial port output until I put the setSysteTime code into a seperate thread.
I have added the Convert.ToUInt16 as a test, initially, I was setting iHours etc as an int and casting it to a ushort - I still got the same delay
If I remove the setting of the time in my application I do not experience the delay highlighted above.
Can anyone help with what I am doing wrong?
Cheers
Peter
Code
- SYSTEMTIME SystemTime = new SYSTEMTIME();
- GetSystemTime(ref SystemTime);
- UInt16 iHours = Convert.ToUInt16(((((bCopyOfRxBufferToSetDateTime[5]) & 0x0f) * 10) + (bCopyOfRxBufferToSetDateTime[6] & 0x0f)));
- UInt16 iMinutes = Convert.ToUInt16(((((bCopyOfRxBufferToSetDateTime[7]) & 0x0f) * 10) + (bCopyOfRxBufferToSetDateTime[8] & 0x0f)));
- UInt16 iMonth = Convert.ToUInt16(((((bCopyOfRxBufferToSetDateTime[9]) & 0x0f) * 10) + (bCopyOfRxBufferToSetDateTime[10] & 0x0f)));
- UInt16 iDay = Convert.ToUInt16(((((bCopyOfRxBufferToSetDateTime[11]) & 0x0f) * 10) + (bCopyOfRxBufferToSetDateTime[12] & 0x0f)));
- UInt16 iYear = Convert.ToUInt16(((((bCopyOfRxBufferToSetDateTime[13]) & 0x0f) * 10) + (bCopyOfRxBufferToSetDateTime[14] & 0x0f)));
- // The year needs to be 4 digit format i.e. 2011
- iYear += 2000;
- SystemTime.wHour = (ushort)iHours;
- SystemTime.wMinute = (ushort)iMinutes;
- SystemTime.wMonth = (ushort)iMonth;
- SystemTime.wDay = (ushort)iDay;
- SystemTime.wYear = (ushort)iYear;
- try
- {
- SetSystemTime(ref SystemTime);
- }
- catch (Exception ex)
- {
- MessageBox.Show("Error setting DateTime " + ex);
- }