vb.net - How to get the loading time of a web page in Windows Service Application using HttpWebRequest -
i'm looking code me loading time of web page without using webbrowser() in windows service application.
i run through different methods, don't quite it.
please me solve problem.
this function should trick:
public function webpageresponsetime(byval url string) timespan dim sw new system.diagnostics.stopwatch sw.start() dim wrequest webrequest = httpwebrequest.create(url) using httpresponse httpwebresponse = directcast(wrequest.getresponse(), httpwebresponse) if httpresponse.statuscode = httpstatuscode.ok sw.stop() return sw.elapsed end if end using end function this take downloading of source code account. if want calculate how long time takes download source code , render page you'd have use webbrowser class.
how works:
the function declares , starts stopwatch used calculating how long operation took, creates web request specified url. downloads entire page's source code (via httpwebresponse) , after checks response's statuscode.
statuscode.ok (which http status code 200) means request succeeded , requested information (the web page's source code) in response, we're not gonna use source code let response disposed later using/end using block.
and lastly function stops stopwatch , returns elapsed time (how long took download web page's source) you.
example use:
dim pageloadtime timespan = webpageresponsetime("http://www.microsoft.com/") messagebox.show("response took: " & pageloadtime.tostring())
Comments
Post a Comment