Powershell - Form can I continuous update the form using Start-Sleep
I am new in Powershell but not to programing I have created a form to monitor web server availablility I used Primalforms 2011 which is quite good. The script works fine and the result is as expected.
The next step is to continuously check the webservers at a 10 minute interval.
My question is how can I achieve this from within yhe Powershell form. I can create a another scrip开发者_开发百科t to call the script every 10 minutes but that is not a smart way(IMHO).
What I would like is to call the Webcheck function every 10 minutes from withing the form, check the pages and update the status accodingly.
Is there some documentation on how the Poweshell form intenals work or is it trial and error? It is per se possible.
Look at the asynchronous event handling in PSH2: the help for Register-ObjectEvent
includes an example with a timer.
(A web search might be able to find a fuller example of PowerShell + GUI + Timer. Eg. http://www.sapien.com/blog/2011/08/09/primalforms-2011-spotlight-on-the-timer-control/)
Not an answer per se but personally I prefer a monitoring solution to be more than a GUI running on a machine. Of course it depends on the requirements\SLA of what you are monitoring and a GUI only solution has many advantages.
Having some form of scheduling software running a script that updates a datafile or database and then have a GUI read that would be my preferred way.
You could do it on a simple level with windows scheduled tasks. If you don't want to use a database you could use Export\Import-CliXML for very quick and easy data storage. Have the GUI check for a new\updated file every X minute(s) and load it if it's new.
Something I've done when using Sapien is to write all my functional code in PowerShell modules and have the GUI call the modules cmdlets. I like the idea of keeping the display different from the functionality - like MVC in web dev. It's very useful if you want to reuse the function from a script.
精彩评论