@karloromic:
I think you make yourself things complicated.
The timer wakes up all n milliseconds - 5000 in your case.
You don't need to start a thread to detect your network connection. Just place the code inside the procedure Timer1Timer. Then you have all that you need.
If you insist on using a thread then set on creating the thread
Then you don't have to free the thread when he is finished.
That's all.
Winni
If i place the code inside procedure OnTimer then the application freezes until connection is made and all checks return result, that can take up to 10 seconds depending on connection speed and latency, and for all that time my program would be frozen.
//set on creating the thread
FreeOnTerminate := True;
I did.
TTimer works fine as stated by
ASerge and also tested by me the same way.
The problem is in my code.
My source code is too big to be pasted here but i can explain.
- TTimer is created and its interval value is 5000 and is enabled on form create
Repeating this
- OnTimer disables itself and starts new Thread(CreateSuspended)
- Thread.OnCreate calls inherited Create(CreateSuspended) and sets
FreeOnTerminate := True;
- OnTimer Starts the thread
- Thread execute internet check code and on the end of Execute updates data to form with Synchronize(@UpdateStatus);
- UpdateStatus method updates data and when finished updating data, enables TTimer again
End Repeat
You can imagine Sleep and Wake event in any time of this code