Last active
December 10, 2015 15:28
-
-
Save hagbarddenstore/4454278 to your computer and use it in GitHub Desktop.
A simple example that shows the principle of opening late and closing early.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public void TheWrongWay() | |
| { | |
| var connection = new SqlConnection(...); | |
| connection.Open(); | |
| DoSomethingTimeConsumingThatDoesNotUseTheDatabase(); | |
| // execute query | |
| connection.Close(); | |
| } | |
| public void TheRightWay() | |
| { | |
| var connection = new SqlConnection(...); | |
| DoSomethingTimeConsumingThatDoesNotUseTheDatabase(); | |
| connection.Open(); | |
| // execute query | |
| connection.Close(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment