Solved

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

Posted on 2003-11-19
3
226 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
  • 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

This is an explanation of a simple data model to help parse a JSON feed
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

757 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now