HighTechTalks DotNet Forums  

Displaying the Start Time

Visual Studio.net (General) microsoft.public.vsnet.general


Discuss Displaying the Start Time in the Visual Studio.net (General) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
JungleJim74
 
Posts: n/a

Default Displaying the Start Time - 06-20-2009 , 03:26 PM






This program makes 2 billion computations and I try to display the Start
Time in a TextBox when the program starts and then display the Ending Time in
another TextBox after all the computations are completed. But it doesn't
display anything until all the computations are completed and then the Start
Time and Ending Time are the same.

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
'Starts the computation
Dim StartTime As DateTime = DateTime.Now 'for calc of elapsed time
Dim ElapsedTime As TimeSpan 'for calc of elapsed time
Dim i As Long 'Loop control variable
Dim result As Double

'TextBox2.Text = DateTime.Now.ToString
TextBox2.Text = StartTime.ToString
'Console.Write(StartTime)
'I replaced the "Thread.Sleep(5000) with the For loop below
'Thread.Sleep(5000) 'sleep for 5 seconds

For i = 1 To 2000000000
result = ((9.154 * 33 - 111.268) / (5.539 - 4.56501))
Next

ElapsedTime = DateTime.op_Subtraction(DateTime.Now, StartTime)

Dim ElapsedTimeText As String

Dim EndingTime As DateTime = DateTime.Now

'ElapsedTimeText = String.Format("{0,2:#0'h'} {1,3:#0'm'} & _
' "{2,3:#0's'} {3,7:##0'ms'}", _
ElapsedTimeText = String.Format("{1,3:#0'm'} {2,3:#0's'} {3,7:##0'ms'}", _
ElapsedTime.Hours, ElapsedTime.Minutes, ElapsedTime.Seconds,
ElapsedTime.Milliseconds)


'Bob wrote this as this is his code modified a little: although this is
my code I don't understand how I get away with the above call to
'String.Format as the overloaded String.Format method doesn't, as far as
I can see,
'support this number of arguments

TextBox1.Visible = True
TextBox8.Visible = True
TextBox5.Visible = True
TextBox6.Visible = True
TextBox7.Visible = True
TextBox9.Visible = True
TextBox10.Visible = True

'MsgBox("My formatting yields: " & ElapsedTimeText)

'MsgBox("TimeSpan.ToString yields: " & ElapsedTime.ToString)

TextBox4.Text = StartTime.ToString

TextBox6.Text = ElapsedTimeText

TextBox7.Text = ElapsedTime.ToString

TextBox8.Text = (i - 1).ToString

TextBox10.Text = result.ToString

End Sub

End Class

Is there a way to get this program to display the Start Time in a TextBox
immediately when the program starts running and then about 9 seconds later
display the Ending Time? Thanks in advance for your help. JungleJim74

Reply With Quote
  #2  
Old   
Quack
 
Posts: n/a

Default RE: Displaying the Start Time - 06-21-2009 , 09:59 AM






You are using an application (button2_click event). Try using
application.doevents after each call to the clock. It will refresh your
textbox then and there.
--
Quack,
I wouldn''t be asking this if I were anything but...


"JungleJim74" wrote:

Quote:
This program makes 2 billion computations and I try to display the Start
Time in a TextBox when the program starts and then display the Ending Time in
another TextBox after all the computations are completed. But it doesn't
display anything until all the computations are completed and then the Start
Time and Ending Time are the same.

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
'Starts the computation
Dim StartTime As DateTime = DateTime.Now 'for calc of elapsed time
Dim ElapsedTime As TimeSpan 'for calc of elapsed time
Dim i As Long 'Loop control variable
Dim result As Double

'TextBox2.Text = DateTime.Now.ToString
TextBox2.Text = StartTime.ToString
'Console.Write(StartTime)
'I replaced the "Thread.Sleep(5000) with the For loop below
'Thread.Sleep(5000) 'sleep for 5 seconds

For i = 1 To 2000000000
result = ((9.154 * 33 - 111.268) / (5.539 - 4.56501))
Next

ElapsedTime = DateTime.op_Subtraction(DateTime.Now, StartTime)

Dim ElapsedTimeText As String

Dim EndingTime As DateTime = DateTime.Now

'ElapsedTimeText = String.Format("{0,2:#0'h'} {1,3:#0'm'} & _
' "{2,3:#0's'} {3,7:##0'ms'}", _
ElapsedTimeText = String.Format("{1,3:#0'm'} {2,3:#0's'} {3,7:##0'ms'}", _
ElapsedTime.Hours, ElapsedTime.Minutes, ElapsedTime.Seconds,
ElapsedTime.Milliseconds)


'Bob wrote this as this is his code modified a little: although this is
my code I don't understand how I get away with the above call to
'String.Format as the overloaded String.Format method doesn't, as far as
I can see,
'support this number of arguments

TextBox1.Visible = True
TextBox8.Visible = True
TextBox5.Visible = True
TextBox6.Visible = True
TextBox7.Visible = True
TextBox9.Visible = True
TextBox10.Visible = True

'MsgBox("My formatting yields: " & ElapsedTimeText)

'MsgBox("TimeSpan.ToString yields: " & ElapsedTime.ToString)

TextBox4.Text = StartTime.ToString

TextBox6.Text = ElapsedTimeText

TextBox7.Text = ElapsedTime.ToString

TextBox8.Text = (i - 1).ToString

TextBox10.Text = result.ToString

End Sub

End Class

Is there a way to get this program to display the Start Time in a TextBox
immediately when the program starts running and then about 9 seconds later
display the Ending Time? Thanks in advance for your help. JungleJim74

Reply With Quote
  #3  
Old   
AMercer
 
Posts: n/a

Default RE: Displaying the Start Time - 06-21-2009 , 10:12 AM



As an alternative to doevents, after
TextBox2.Text = StartTime.ToString
do
TextBox2.Update
I prefer avoiding doevents whenever possible.

"Quack" wrote:

Quote:
You are using an application (button2_click event). Try using
application.doevents after each call to the clock. It will refresh your
textbox then and there.
--
Quack,
I wouldn''t be asking this if I were anything but...


"JungleJim74" wrote:

This program makes 2 billion computations and I try to display the Start
Time in a TextBox when the program starts and then display the Ending Time in
another TextBox after all the computations are completed. But it doesn't
display anything until all the computations are completed and then the Start
Time and Ending Time are the same.

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
'Starts the computation
Dim StartTime As DateTime = DateTime.Now 'for calc of elapsed time
Dim ElapsedTime As TimeSpan 'for calc of elapsed time
Dim i As Long 'Loop control variable
Dim result As Double

'TextBox2.Text = DateTime.Now.ToString
TextBox2.Text = StartTime.ToString
'Console.Write(StartTime)
'I replaced the "Thread.Sleep(5000) with the For loop below
'Thread.Sleep(5000) 'sleep for 5 seconds

For i = 1 To 2000000000
result = ((9.154 * 33 - 111.268) / (5.539 - 4.56501))
Next

ElapsedTime = DateTime.op_Subtraction(DateTime.Now, StartTime)

Dim ElapsedTimeText As String

Dim EndingTime As DateTime = DateTime.Now

'ElapsedTimeText = String.Format("{0,2:#0'h'} {1,3:#0'm'} & _
' "{2,3:#0's'} {3,7:##0'ms'}", _
ElapsedTimeText = String.Format("{1,3:#0'm'} {2,3:#0's'} {3,7:##0'ms'}", _
ElapsedTime.Hours, ElapsedTime.Minutes, ElapsedTime.Seconds,
ElapsedTime.Milliseconds)


'Bob wrote this as this is his code modified a little: although this is
my code I don't understand how I get away with the above call to
'String.Format as the overloaded String.Format method doesn't, as far as
I can see,
'support this number of arguments

TextBox1.Visible = True
TextBox8.Visible = True
TextBox5.Visible = True
TextBox6.Visible = True
TextBox7.Visible = True
TextBox9.Visible = True
TextBox10.Visible = True

'MsgBox("My formatting yields: " & ElapsedTimeText)

'MsgBox("TimeSpan.ToString yields: " & ElapsedTime.ToString)

TextBox4.Text = StartTime.ToString

TextBox6.Text = ElapsedTimeText

TextBox7.Text = ElapsedTime.ToString

TextBox8.Text = (i - 1).ToString

TextBox10.Text = result.ToString

End Sub

End Class

Is there a way to get this program to display the Start Time in a TextBox
immediately when the program starts running and then about 9 seconds later
display the Ending Time? Thanks in advance for your help. JungleJim74

Reply With Quote
  #4  
Old   
eBob.com
 
Posts: n/a

Default Re: Displaying the Start Time - 06-27-2009 , 08:01 PM



I didn't study your code, but when I saw the For loop my first thought was
that it wouldn't take much optimization to eliminate it. The compiler could
easily recognize that the calculation could be moved outside of the loop.
And then could easily see that there was no point to executing the loop. I
don't know if the .NET compilers do any optimization. What happens if you
Sleep instead of doing the For loop? Do you see a difference in the time
stamps then?

Bob


"JungleJim74" <JungleJim74 (AT) discussions (DOT) microsoft.com> wrote

Quote:
This program makes 2 billion computations and I try to display the Start
Time in a TextBox when the program starts and then display the Ending Time
in
another TextBox after all the computations are completed. But it doesn't
display anything until all the computations are completed and then the
Start
Time and Ending Time are the same.

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
'Starts the computation
Dim StartTime As DateTime = DateTime.Now 'for calc of elapsed time
Dim ElapsedTime As TimeSpan 'for calc of elapsed time
Dim i As Long 'Loop control variable
Dim result As Double

'TextBox2.Text = DateTime.Now.ToString
TextBox2.Text = StartTime.ToString
'Console.Write(StartTime)
'I replaced the "Thread.Sleep(5000) with the For loop below
'Thread.Sleep(5000) 'sleep for 5 seconds

For i = 1 To 2000000000
result = ((9.154 * 33 - 111.268) / (5.539 - 4.56501))
Next

ElapsedTime = DateTime.op_Subtraction(DateTime.Now, StartTime)

Dim ElapsedTimeText As String

Dim EndingTime As DateTime = DateTime.Now

'ElapsedTimeText = String.Format("{0,2:#0'h'} {1,3:#0'm'} & _
' "{2,3:#0's'} {3,7:##0'ms'}", _
ElapsedTimeText = String.Format("{1,3:#0'm'} {2,3:#0's'}
{3,7:##0'ms'}", _
ElapsedTime.Hours, ElapsedTime.Minutes, ElapsedTime.Seconds,
ElapsedTime.Milliseconds)


'Bob wrote this as this is his code modified a little: although this is
my code I don't understand how I get away with the above call to
'String.Format as the overloaded String.Format method doesn't, as far
as
I can see,
'support this number of arguments

TextBox1.Visible = True
TextBox8.Visible = True
TextBox5.Visible = True
TextBox6.Visible = True
TextBox7.Visible = True
TextBox9.Visible = True
TextBox10.Visible = True

'MsgBox("My formatting yields: " & ElapsedTimeText)

'MsgBox("TimeSpan.ToString yields: " & ElapsedTime.ToString)

TextBox4.Text = StartTime.ToString

TextBox6.Text = ElapsedTimeText

TextBox7.Text = ElapsedTime.ToString

TextBox8.Text = (i - 1).ToString

TextBox10.Text = result.ToString

End Sub

End Class

Is there a way to get this program to display the Start Time in a TextBox
immediately when the program starts running and then about 9 seconds later
display the Ending Time? Thanks in advance for your help. JungleJim74

Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.