Solved

C# (Urgent): messure how long a script needs

Posted on 2003-11-19
3
270 Views
Last Modified: 2010-04-17
I need to know how long the execution of a script with DB connections take.

In VB it was done like this:
<html>
<%
startTime = Timer
......
// some DB connections etc...
......
%>
<%= Timer - StartTime %>
</html>


How do you do this best/most effective in C# ?
thank you
0
Comment
Question by:Smoerble
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 5

Expert Comment

by:TRUENEUTRAL
ID: 9780482
That looks like ASP code (VBScript).  C# is compiled code.  You will need to use ASP.NET (in which case you can still use the VBScript you listed above)

Perhaps you should elaborate?
0
 

Author Comment

by:Smoerble
ID: 9780519
THanks for your comment, but I know that C# is compiled code, the question is how would you do this in C#?
E.g. I could get the startTime in the PageLoad-Event, but what are the exact classes/methods I need and how woudl you calculate the result?

thank you
0
 
LVL 5

Accepted Solution

by:
TRUENEUTRAL earned 250 total points
ID: 9781913
Here's how you can get it with vb code... not sure how to get ASP.NET to use C# code, though.

Public Class WebForm1
    Inherits System.Web.UI.Page
    Protected WithEvents TextBox1 As System.Web.UI.WebControls.TextBox

    Public load_time As Double

#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
        load_time = Now().ToOADate

    End Sub

#End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here
    End Sub

    Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)
        writer.Write(load_time.ToString)
        writer.Write("<br>")
        writer.Write(Now().ToOADate.ToString)



    End Sub
End Class
0

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A short article about problems I had with the new location API and permissions in Marshmallow
Make the most of your online learning experience.
Simple Linear Regression
Starting up a Project

632 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question