In c# programming if we include function call within the button click with definition more than 20 lines..........does it improves the performance (speed) of the program when compared with writing that 20lines within the button click function ...............

Recommended Answers

All 7 Replies

It's faster to have the code inside the button click event as any call to a method has some overhead. But we are talking about millionths of a second, you won't notice.

It won't be faster at all. Saying that it is 20 lines is really meaningless, because 1 of those lines might be really slow. If you want to post some code, we might be able to help you further.

Another thing you might be able to do is use the BackgroundWorker to perform this operation on another thread.

It won't be faster at all. Saying that it is 20 lines is really meaningless, because 1 of those lines might be really slow. If you want to post some code, we might be able to help you further.

It is irrelevant how long the 20 lines take to execute as that is a constant whether they are in a different method or in the button click. The only difference is how long it takes to call the method. And as I said before the difference is in the millionths of a second. No one will notice when they click the button.

The first computer I worked with at home was this one It runned at a clockspeed of 3 MHz. And 3 MHz was fast in these days! The computer I'm typing this on runs at 2.2 GHz. So the overhead of calling a method really does not matter that much. In fact it is even better to call a method in the click handler of your button. What if you want to do the same action from a menu? You only would have just one method to maintain, instead of many of the same lines of code sprinkled al over your program.

thank u..............

The first computer I worked with at home was this one

First computer I worked with was this. Yes, those are front panel switches, you entered everything in binary one byte at a time.

Those were the days...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.