none
TextChanged event in C#

    Question

  • Is it advisable to call a method in the TextChanged event of the textbox in C# containing string manipulation or would it be more efficient to have the code itself in the event? I am concerned that it would take more processing power when calling the method on every key pressed.

    a&h

    Tuesday, March 20, 2012 8:38 AM

Answers

  • In either cases, you are going to execute the code.

    The difference is that you would place the code in a different method and call the method. .NET even sometimes optimizes the code by removing unnecessary methods. So this should be any problem. Boxing and Unboxing would be one if working with value types passed as reference.

    " I am concerned that it would take more processing power when calling the method on every key pressed.": If you are working with Key press event then you will have the same. As you are using TextChanged event, this event will be fired when you tab out of the textbox.


    Welcome to MSDN Forums.
    Feel free to ask your questions and Please Note to Vote all helpful topics and Mark all answering posts.

    You Value Community's efforts and Community values your faith.
    - Arun Kumar Allu

    • Proposed as answer by Neddy Ren Wednesday, March 21, 2012 7:40 AM
    • Marked as answer by Neddy Ren Wednesday, March 28, 2012 6:01 AM
    Tuesday, March 20, 2012 8:47 AM

All replies

  • Is it advisable to call a method in the TextChanged event of the textbox in C# containing string manipulation or would it be more efficient to have the code itself in the event? I am concerned that it would take more processing power when calling the method on every key pressed.

    a&h

    Tuesday, March 20, 2012 6:46 AM
  • Hi heinkaner, your question is best suited to be posted in the Visual C# General Forum as this forum is meant for issues related to .NET framework setup issues, thanks!
    Tuesday, March 20, 2012 7:33 AM
  • In either cases, you are going to execute the code.

    The difference is that you would place the code in a different method and call the method. .NET even sometimes optimizes the code by removing unnecessary methods. So this should be any problem. Boxing and Unboxing would be one if working with value types passed as reference.

    " I am concerned that it would take more processing power when calling the method on every key pressed.": If you are working with Key press event then you will have the same. As you are using TextChanged event, this event will be fired when you tab out of the textbox.


    Welcome to MSDN Forums.
    Feel free to ask your questions and Please Note to Vote all helpful topics and Mark all answering posts.

    You Value Community's efforts and Community values your faith.
    - Arun Kumar Allu

    • Proposed as answer by Neddy Ren Wednesday, March 21, 2012 7:40 AM
    • Marked as answer by Neddy Ren Wednesday, March 28, 2012 6:01 AM
    Tuesday, March 20, 2012 8:47 AM