Click here to Skip to main content
15,912,897 members
Home / Discussions / C#
   

C#

 
AnswerRe: How know the state connected for udp client Pin
Dave Kreskowiak6-May-15 17:23
mveDave Kreskowiak6-May-15 17:23 
GeneralRe: How know the state connected for udp client Pin
hasan hadi6-May-15 23:29
hasan hadi6-May-15 23:29 
GeneralRe: How know the state connected for udp client Pin
Dave Kreskowiak7-May-15 1:24
mveDave Kreskowiak7-May-15 1:24 
GeneralRe: How know the state connected for udp client Pin
hasan hadi7-May-15 3:17
hasan hadi7-May-15 3:17 
AnswerRe: How know the state connected for udp client Pin
F-ES Sitecore6-May-15 23:28
professionalF-ES Sitecore6-May-15 23:28 
GeneralRe: How know the state connected for udp client Pin
hasan hadi6-May-15 23:35
hasan hadi6-May-15 23:35 
AnswerRe: How know the state connected for udp client Pin
hasan hadi10-May-15 16:12
hasan hadi10-May-15 16:12 
QuestionSQL Server Connection Best Practice Pin
JBHowl6-May-15 8:58
JBHowl6-May-15 8:58 
Hello all, I have a quick question. I have a service running that continually checks the database for a record, if a record exist then it process the record and deletes it. The service starts a thread that runs a while look until it tells it to stop. Is it better to create the connection inside or outside of the loop? Keep in mind that this loop could run for days. See below for the two options:

C#
//In this example, I create the connection and close for each interval of the loop
            while (!stopEvent.WaitOne(0, false))
            {
                using (SqlConnection dbConnection = new SqlConnection(connectionString))
                {
                    dbConnection.Open();

                    using (SqlCommand dbCommand = new SqlCommand("SELECT * FROM [TableName]", dbConnection))
                    {
                        using (SqlDataReader dbReader = dbCommand.ExecuteReader())
                        {
                            if (dbReader.Read())
                            {
                                //There is a record, process it and delete it.
                            }
                        }
                    }
                }

                System.Threading.Thread.Sleep(100);
            }

            //In this example, I create one connection until the loop completes then I close it.
            using (SqlConnection dbConnection = new SqlConnection(connectionString))
            {
                dbConnection.Open();

                while (!stopEvent.WaitOne(0, false))
                {
                    using (SqlCommand dbCommand = new SqlCommand("SELECT * FROM [TableName]", dbConnection))
                    {
                        using (SqlDataReader dbReader = dbCommand.ExecuteReader())
                        {
                            if (dbReader.Read())
                            {
                                //There is a record, process it and delete it.
                            }
                        }
                    }
                }

                System.Threading.Thread.Sleep(100);
            }

AnswerRe: SQL Server Connection Best Practice Pin
Richard Deeming6-May-15 9:28
mveRichard Deeming6-May-15 9:28 
AnswerRe: SQL Server Connection Best Practice Pin
Dave Kreskowiak6-May-15 11:11
mveDave Kreskowiak6-May-15 11:11 
AnswerRe: SQL Server Connection Best Practice Pin
F-ES Sitecore6-May-15 22:39
professionalF-ES Sitecore6-May-15 22:39 
QuestionCreating Large, Blank Bitmaps Pin
JBHowl6-May-15 3:39
JBHowl6-May-15 3:39 
AnswerRe: Creating Large, Blank Bitmaps Pin
Dave Kreskowiak6-May-15 4:15
mveDave Kreskowiak6-May-15 4:15 
GeneralRe: Creating Large, Blank Bitmaps Pin
JBHowl6-May-15 4:41
JBHowl6-May-15 4:41 
GeneralRe: Creating Large, Blank Bitmaps Pin
Eddy Vluggen6-May-15 5:14
professionalEddy Vluggen6-May-15 5:14 
GeneralRe: Creating Large, Blank Bitmaps Pin
Dave Kreskowiak6-May-15 11:07
mveDave Kreskowiak6-May-15 11:07 
AnswerRe: Creating Large, Blank Bitmaps Pin
Pete O'Hanlon6-May-15 5:00
mvePete O'Hanlon6-May-15 5:00 
GeneralRe: Creating Large, Blank Bitmaps Pin
JBHowl6-May-15 5:03
JBHowl6-May-15 5:03 
GeneralRe: Creating Large, Blank Bitmaps Pin
Pete O'Hanlon6-May-15 8:50
mvePete O'Hanlon6-May-15 8:50 
AnswerRe: Creating Large, Blank Bitmaps Pin
OriginalGriff6-May-15 6:14
mveOriginalGriff6-May-15 6:14 
GeneralRe: Creating Large, Blank Bitmaps Pin
JBHowl6-May-15 7:16
JBHowl6-May-15 7:16 
QuestionHow can I use webcam in WebBrowser Control? Pin
Member 116126625-May-15 17:45
Member 116126625-May-15 17:45 
AnswerRe: How can I use webcam in WebBrowser Control? Pin
Dr Gadgit6-May-15 2:14
Dr Gadgit6-May-15 2:14 
QuestionC# Get Audio File From Resources Pin
Kevin Marois5-May-15 9:03
professionalKevin Marois5-May-15 9:03 
AnswerRe: C# Get Audio File From Resources Pin
Sascha Lefèvre5-May-15 10:28
professionalSascha Lefèvre5-May-15 10:28 

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.