Click here to Skip to main content
15,886,137 members
Home / Discussions / C#
   

C#

 
AnswerRe: Acquiring a property value Pin
OriginalGriff25-Jul-13 21:39
mveOriginalGriff25-Jul-13 21:39 
AnswerRe: Acquiring a property value Pin
Blubbo26-Jul-13 4:38
Blubbo26-Jul-13 4:38 
GeneralRe: Acquiring a property value Pin
PIEBALDconsult26-Jul-13 7:55
mvePIEBALDconsult26-Jul-13 7:55 
GeneralRe: Acquiring a property value Pin
Richard MacCutchan26-Jul-13 22:26
mveRichard MacCutchan26-Jul-13 22:26 
AnswerRe: Acquiring a property value Pin
coolcat22731-Jul-13 11:29
coolcat22731-Jul-13 11:29 
QuestionPower management hybernation is causing my application to hang ... Pin
turbosupramk325-Jul-13 2:50
turbosupramk325-Jul-13 2:50 
AnswerRe: Power management hybernation is causing my application to hang ... Pin
turbosupramk326-Jul-13 3:47
turbosupramk326-Jul-13 3:47 
Questionusing System.Diagnostics.Stopwatch in an Button_Click Event: unusual results in specific test case Pin
BillWoodruff25-Jul-13 0:55
professionalBillWoodruff25-Jul-13 0:55 
Win 8/64 Visual Studio 2012 v.3, WinForms C#, FrameWork 4.5: no use of explicit threading in the project.

I've come to rely on using 'Stopwatch for a timer, and I am surprised to find, in a current project, a huge difference between what I observe, and what Stopwatch reports.

I have a very complex generic class, whose generic Types include other generic Type classes. I am able to create any number of instances of the outer class without a problem, and verify their contents.

Using Stopwatch to time the creation of the instances seems to give results consistent with what I observe. I'm not bothering, in this case, to do a "dry run" to pre-JIT.

Where what I observe really varies from what Stopwatch returns is: in the case where I loop through all the created instances in the outer class, and fill a StringBuilder with a complete kind of "report" on all the instances of the outer class, and all the various instances of the inner classes.

The inner classes have public Guid properties, set when their constructor is called (via 'private set).

If I create 10,000 instances of the outer class, and each of (in this case #2) of its inner classes have 10 objects each initialized as they are created. I end up with potentially 20k Guids, 100k each of the inner class contents. So, the resulting "report" (adding in tab characters, and other formatting) will come out to about 250k lines of text, containing about 4mb of characters.

From pressing the button that generates the "report" to seeing the report-TextBox filled, takes around thirty seconds, but Stopwatch is reporting the operation took 300~800 milliseconds.

Hypotheses:

1. there's something about using Stopwatch in the scope of a Button_Click EventHandler that leads to errors. Threading issue ? Doubtful, imho, since object creation seems to time okay.

2. there's something about using StringBuilder, and then converting to 'string, and setting the 'Text property of a TextBox that compromises Stopwatch. Wrapping TextBox refresh in 'SuspendLayout and 'ResumeLayout seem to have no appreciable effect.

Here's the code as stripped-down as possible to indicate how the report is being generated, and Stopwatch is being used:
C#
sb.Clear();

// forcing GC, and waiting for finalizers to unqueue has no effect here
// GC.Collect();
// GC.WaitForPendingFinalizers();

// watch2 is an already declared System.Diagnostics.Stopwatch
// reset the watch, start it
watch2.Reset();
watch2.Start();

// fill the StringBuilder, 'sb
for (int i = 0; i < KVPList.Count; i++)
{
    // a whole-lot-of-looping-going-on
}

// tbReport is a TextBox with 'MultiLine = 'true
// tbReport.SuspendLayout();
    tbReport.Text = sb.ToString();
// tbReport.ResumeLayout();

watch2.Stop();

// a TextBox used to report results
tbEventReport.Text = "Report Displayed: Time(ms): " + watch2.Elapsed.Milliseconds
Appreciate any suggestions, or ideas; very high-precision timing is not really needed here.

thanks, Bill

~
“This isn't right; this isn't even wrong." Wolfgang Pauli, commenting on a physics paper submitted for a journal

AnswerRe: using System.Diagnostics.Stopwatch in an Button_Click Event: unusual results in specific test case Pin
Dave Kreskowiak25-Jul-13 1:15
mveDave Kreskowiak25-Jul-13 1:15 
GeneralRe: using System.Diagnostics.Stopwatch in an Button_Click Event: unusual results in specific test case Pin
BillWoodruff25-Jul-13 21:48
professionalBillWoodruff25-Jul-13 21:48 
GeneralRe: using System.Diagnostics.Stopwatch in an Button_Click Event: unusual results in specific test case Pin
Dave Kreskowiak26-Jul-13 7:00
mveDave Kreskowiak26-Jul-13 7:00 
GeneralRe: using System.Diagnostics.Stopwatch in an Button_Click Event: unusual results in specific test case Pin
BillWoodruff30-Jul-13 4:57
professionalBillWoodruff30-Jul-13 4:57 
GeneralRe: using System.Diagnostics.Stopwatch in an Button_Click Event: unusual results in specific test case Pin
Dave Kreskowiak30-Jul-13 5:46
mveDave Kreskowiak30-Jul-13 5:46 
AnswerRe: using System.Diagnostics.Stopwatch in an Button_Click Event: unusual results in specific test case PinPopular
Alan N25-Jul-13 4:27
Alan N25-Jul-13 4:27 
GeneralRe: using System.Diagnostics.Stopwatch in an Button_Click Event: unusual results in specific test case Pin
BillWoodruff25-Jul-13 21:13
professionalBillWoodruff25-Jul-13 21:13 
QuestionParamerterized OleDB Query Pin
gautamn199025-Jul-13 0:21
gautamn199025-Jul-13 0:21 
AnswerRe: Paramerterized OleDB Query Pin
Dave Kreskowiak25-Jul-13 1:17
mveDave Kreskowiak25-Jul-13 1:17 
GeneralRe: Paramerterized OleDB Query Pin
gautamn199025-Jul-13 19:28
gautamn199025-Jul-13 19:28 
GeneralRe: Paramerterized OleDB Query Pin
Dave Kreskowiak26-Jul-13 2:52
mveDave Kreskowiak26-Jul-13 2:52 
GeneralRe: Paramerterized OleDB Query Pin
gautamn199028-Jul-13 19:03
gautamn199028-Jul-13 19:03 
AnswerRe: Paramerterized OleDB Query Pin
PIEBALDconsult25-Jul-13 14:19
mvePIEBALDconsult25-Jul-13 14:19 
GeneralRe: Paramerterized OleDB Query Pin
gautamn199025-Jul-13 19:45
gautamn199025-Jul-13 19:45 
GeneralRe: Paramerterized OleDB Query Pin
PIEBALDconsult26-Jul-13 7:58
mvePIEBALDconsult26-Jul-13 7:58 
QuestionDataGridview ComboBox Filter Pin
Awais Jan24-Jul-13 23:44
Awais Jan24-Jul-13 23:44 
Questionproblem with datagridview in windows application Pin
Arun kumar Gautam24-Jul-13 20:59
Arun kumar Gautam24-Jul-13 20:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.