Client connect without holding up thread

I have a lamp that cycles through rgb colours using pwm. At set intervals it polls my webpage to retrieve an integer x and pulses (up to white and back to the original colour) x times. This is mostly working now but I have a couple of questions regarding programming (and more specifically the ethernet library).

Is there a way to use client.connect() without it holding up the thread? In the loop function I'm checking the display state and seeing whether it needs to update and then performing whatever data access function is needed next. Currently my lamp colour stops cycling for the duration of the connect - usually this isn't that noticable but if it fails to connect it can cause the colour to stick for a while.

I'm also still having a few problems with connections not clearing properly and failing to connect after a while. I've spent quite a lot of time on this problem. I tried a patched copy of the ethernet library and the ethernet2 library but I still have issues. The most stability I've managed to get was by just calling the client.stop() function when I receive the "data finished" character from my site and not trying to reconnect for at least 10 seconds - it's not perfect though. What is the best way to check whether the connection has been properly cleared?

Maybe I've not got an answer because I'm over complicating my question - How do you do something that needs constant updating when you also need to do something that holds up the thread for a while?

Do you need a second device or is there a programming trick?


I am not sure I got your question right but with single task single processor the arduino is the only option is interrupts. Have a look here:
nice article here:

Thanks - that looks like just what I need (although I'm going to have to do some more reading to know exactly what it is I need to do).

Do you know whether I can still use the internal timers if they're also being used for PWM or would I need to get an external timer?