Best Performance Practice Question

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a question about design, performance, and code reusability. Which one of these would be the best as far as performance/speed
Send a textbox to a public class to check it and process/not process the text in it (which would be called from many different forms-would be reusable
-or
Validate it locally on each for

Would there be a major difference in performance/speed? Is there any way to actually see the differences in performance

Thanks
John
 
Would there be a major difference in performance/speed? Is there any way to actually see the differences in performance?

I doubt it. When you send a textbox you're very likely talking about
passing a TextBox argument to a method on the same thread, correct?
That just passes an object reference on the stack which is almost
immeasurably fast. Now if you had to marshal to a different thread
(let alone a remote system) things might be different.
 
Which one of these would be the best as far as performance/speed: Send
a textbox to a public class to check it and process/not process the
text in it (which would be called from many different forms-would be
reusable) -or-
Validate it locally on each form

Send textbox to a single validator/processor function.

The reason is that you would not be sending the textbox itself, just a
pointer to it.

The bigger questions is why are you considering sending a textbox and not
just the string of contents?
Would there be a major difference in performance/speed? Is there any
way to actually see the differences in performance?

Nah, performance would be the same. At most you are sending a pointer.
 
John,
I agree with the others that theres no significant performance
difference as yr only passing references when you pass the text box to a
function. Ideally you'd only have to send the the string to validate/
process or otherwise
Thanks
 
Thanks for the replies, Christoph and gabriel. The reason (I was
thinking) was that I wanted to clear the textbox and set the focus to it
without having to create an if statement in each textbox's click event.
Ex:
bool blnValid = csValidate(strTextBoxText.Text);
if (blnValid)
{
//valid
}
else
{
//invalid-clear and reset focus
}
as opposed to:
csValidate(txtTextBox)

A lot of these forms will be using the same validation comparisons based
on what type of textbox it is, and I wanted to share them all. Is that
a bad idea, or is there some other way that would be better? I'm
definitely open to suggestions. I'm having to rebuild a COBOL program,
and I'm open to anything (except building another COBOL program -
yuccckkk!).
Thanks,
John
 
John said:
The reason (I was thinking) was that I wanted to clear the textbox and
set the focus to it without having to create an if statement in each
textbox's click event.

First of all, you can have all the textboxes use the same OnClick
handler. That's why on the designed the OnClick handler is a drop-down
text box. You can code one handler then for all the other controls
select the same function name.

You can see which textbox triggered the event via the "sender" argument.
Something like this:

private void my_custom_Click(object sender, System.EventArgs e) {
string senderName = ((TextBox)sender).Name;

if (senerName == "TextBox1") {
// Process this.TextBox1
} else if (senderName == "TextBox2") {
// Process this.TextBox2
[..whatever..]
}
}

A lot of these forms will be using the same validation comparisons
based on what type of textbox it is, and I wanted to share them all.
Is that a bad idea, or is there some other way that would be better?

It's a good idea, in cases like this, doing it "the rioght way" will
save you tons of typing and maintenance.
 
gabriel,
Thanks for the advice and the code snippet. I'll definitely use it. I
definitely want to save "tons of typing and maintentance."

John
 
Back
Top