<Script type = "text/javascript"> function showLoading (desc) {$ ("body "). append ("<div id = \" processingdiv \ "style = \" display: none; \ "> <div class = \" popup \ "> <div class = \" popup-body \ "> <div class = \" loading \ "> <span style =' width: 128px; height: 128px; '> </span> <span class = 'splitcontent'> "+ desc +" </span> </div> </div> "); // alert ($ ("head" example .html (); $. openPopupLayer ({na Me: "processing", width: 500, target: "processingdiv"});} function hideLoading () {$. closePopupLayer ('processing'); $ ("# processingdiv "). remove ();} function changeShowStatus () {$. post ("Ajax/ShowHandler. ashx ", {" action ":" ChangeStatusShow "}, function (data) {$ (" # spnServerStatus "). text (data); hideLoading () ;}) ;}var isValidServerStatus = function (data) {if (data = "run") {$ ("# serverStatus" ). Text ("stop" ).css ("color", "red"); changeShowStatus (); // setTimeout (changeShowStatus, 6000);} else if (data = "end ") {$ ("# serverStatus "). text ("START" ).css ("color", "green"); changeShowStatus (); // setTimeout (changeShowStatus, 6000);} else if (data = "NoNormalEnd ") {$ ("# serverStatus "). text ("START" ).css ("color", "green"); changeShowStatus ();} else if (data = "empty") {alert ('the service does not exist! ');} Else if (data = "startfail") {alert ('startup failed! '); $ ("# ServerStatus "). text ("START" ).css ("color", "green"); changeShowStatus ();} else if (data = "stopfail") {alert ("Stop failed! "); $ (" # ServerStatus "). text (" stop ").css (" color "," red "); changeShowStatus ();} else {alert ('Operation failed! '+ Data); window. location. reload () ;}$ (function () {$ ("# serverStatus "). click (function () {var txt = $ ("# serverStatus "). text (); if (txt = "stop") {showLoading ("the service is stopping ...... "); $ (" # spnServerStatus "). text ("stopping... "); $. post ("Ajax/ServerHandler. ashx ", {" action ":" stop "}, isValidServerStatus);} else if (txt =" start ") {showLoading (" the service is starting ...... "); $ (" # spnServerStatus "). text ("starting... "); $. post ("Ajax/ServerHandler. ashx ", {" action ":" start "}, isValidServerStatus) ;}}) ;}</script>
The general processing procedure is as follows:
Public class ServerHandler: IHttpHandler {public void ProcessRequest (HttpContext context) {context. response. contentType = "text/plain"; string action = context. request ["action"]; string serverName = QuarrysClass. windowsServerName; EnumServiceStatus status = CommonClass. getServiceStatus (serverName); if (string. isNullOrEmpty (serverName) {context. response. write ("empty");} if (action = "start ") {Byte [] ver = new byte [1024]; try {// enable the Service if (CommonClass. startWindowsService (serverName) {context. response. write ("run");} else {context. response. write ("startfail") ;}} catch (Exception ex) {context. response. write ("prompt:" + ex. message) ;}} else if (action = "stop") // stop the service {try {if (CommonClass. stopWindowsService (serverName) {// Thread. sleep (6000*3); context. response. write ("end");} else {Context. Response. Write ("stopfail") ;}} catch (Exception ex) {if (ex. Message = "the timeout time has been reached and the operation has not been completed. ") {Context. response. write ("prompt:" + ex. message);} else {context. response. write ("NoNormalEnd") ;}}} public bool IsReusable {get {return false ;}}}