I have an ASP.Net application that calls an Amazon Web Service to start a virtual machine. Once the user clicks to start the machine, the page posts back to show the list of virtual machines. This part is fine. If the virtual machine has a static IP address assigned to it, a separate API function to Amazon needs to be called once the virtual machine is in a “running state.” I don’t want the user to have to kick off the assignment of the static IP, I want it to happen automatically.
My question is should I use a timer and just keep checking if the machine is in running state and then run the second set of code? It seems kind of clunky to me, so I’m not sure if there is any other way (better way) to do this.
Threading this on the server using a single background thread is not a good idea on ASP.NET. Even disregarding the issues of IIS terminating the background thread (which it can and will do when recycling application pools), you are using up a valuable, limited resource (server threads) when you have a relatively plentiful resource (clients) that can call back periodically to check whether the server has come up yet. Because of that, by using a server thread you’d be seriously constraining your scalability. I’d recommend using a client polling approach with a timer, as you originally planned.