Click here to Skip to main content
15,884,298 members
Home / Discussions / C#
   

C#

 
AnswerRe: Override properties in derived classes - some have fixed value, some do not PinPopular
OriginalGriff1-Sep-16 23:13
mveOriginalGriff1-Sep-16 23:13 
GeneralRe: Override properties in derived classes - some have fixed value, some do not Pin
BillWoodruff2-Sep-16 1:49
professionalBillWoodruff2-Sep-16 1:49 
GeneralRe: Override properties in derived classes - some have fixed value, some do not Pin
OriginalGriff2-Sep-16 3:57
mveOriginalGriff2-Sep-16 3:57 
QuestionTimeStamp to PDF Pin
Member 119141971-Sep-16 22:06
Member 119141971-Sep-16 22:06 
QuestionSuggesstions on saving 100s of rowsto the database Pin
Giridhar Aruri1-Sep-16 15:27
Giridhar Aruri1-Sep-16 15:27 
AnswerRe: Suggesstions on saving 100s of rowsto the database Pin
OriginalGriff1-Sep-16 20:22
mveOriginalGriff1-Sep-16 20:22 
AnswerRe: Suggesstions on saving 100s of rowsto the database Pin
Eddy Vluggen1-Sep-16 23:10
professionalEddy Vluggen1-Sep-16 23:10 
QuestionNeed to cancel BackgroundWorker Pin
David_411-Sep-16 13:01
David_411-Sep-16 13:01 
Hello all. I have a background worker that executes a query against an SQL Server database. The user clicks a button and the query runs, then the results of the query go into a datagrid. The users are requesting a Cancel button for the query because the queries can take a very long time to run. So when the user clicks the Run Query button, a small form with a Cancel Button opens. If the user clicks the button, DialogueResult.Cancel is returned and I execute CancelAsync().

Meanwhile, in my DoWork thread, I am preparing to run the query. When I run the query, I execute

adapter3.Fill(GlobalData.g_queryData);

So, there is no loop. Most of the forums I have seen tell you to check Backgroundworker.CancellationPending. The problem is that I am not running in a loop.

So, can someone suggest maybe another approach to canceling a query that is currently running?

Thanks,
David

C#
using (SqlConnection connection = new SqlConnection(GlobalStr.sqlConnStringMetadata))
                {
                    try
                    {
                        connection.Open();

                        /*
                         * DRW 3/10/2016
                         * Added the following Transaction object in order to set the isolation level of all queries
                         * run from MAnDA to to Read Uncommited.
                         */
                        SqlTransaction Transaction = connection.BeginTransaction(IsolationLevel.ReadUncommitted);

                        using (SqlCommand testQuery = new SqlCommand(GlobalStr.previewQueryString, connection))
                        {
                            /*
                             * DRW 3/11/2016
                             * User sets the query timeout value via a textbox on the main form. The value is held in a variable.
                             * testQuery.CommandTimeout = 300;
                             */

                            testQuery.CommandTimeout = m_QueryTimeout;
                            testQuery.Transaction = Transaction;                           

                            using (SqlDataAdapter adapter3 = new SqlDataAdapter(testQuery))
                            {
                                adapter3.Fill(GlobalData.g_queryData);

                                // Open the DataSetViewer form and send the table to it
                                DataSetViewer dsv = new DataSetViewer();
                                dsv.SetSource(GlobalData.g_queryData);
                                // set the dataview classification 05272015
                                string strClassification = string.Format("{0} {1}", GlobalStr.g_classification, GlobalStr.g_releaseability);
                                dsv.setClassification(strClassification);
                                Cursor.Current = Cursors.Default;
                                dsv.ShowDialog();

                                //dataGridView1.DataSource = GlobalData.g_queryData;
                            }
                        }
                        connection.Close();
                    }
                    catch (Exception ex)
                    {
                        /// Print error message
                        MessageBox.Show("The query test failed: " + ex.Message);
                        return;
                    }
                }

AnswerRe: Need to cancel BackgroundWorker Pin
Pete O'Hanlon1-Sep-16 21:01
mvePete O'Hanlon1-Sep-16 21:01 
GeneralRe: Need to cancel BackgroundWorker Pin
David_416-Sep-16 8:12
David_416-Sep-16 8:12 
GeneralRe: Need to cancel BackgroundWorker Pin
Pete O'Hanlon6-Sep-16 9:39
mvePete O'Hanlon6-Sep-16 9:39 
AnswerRe: Need to cancel BackgroundWorker Pin
Gerry Schmitz3-Sep-16 6:53
mveGerry Schmitz3-Sep-16 6:53 
GeneralRe: Need to cancel BackgroundWorker Pin
David_416-Sep-16 8:20
David_416-Sep-16 8:20 
GeneralRe: Need to cancel BackgroundWorker Pin
Gerry Schmitz6-Sep-16 9:08
mveGerry Schmitz6-Sep-16 9:08 
GeneralRe: Need to cancel BackgroundWorker Pin
David_416-Sep-16 9:14
David_416-Sep-16 9:14 
GeneralRe: Need to cancel BackgroundWorker Pin
David_416-Sep-16 9:18
David_416-Sep-16 9:18 
GeneralRe: Need to cancel BackgroundWorker Pin
Gerry Schmitz6-Sep-16 9:48
mveGerry Schmitz6-Sep-16 9:48 
GeneralRe: Need to cancel BackgroundWorker Pin
David_416-Sep-16 10:05
David_416-Sep-16 10:05 
GeneralRe: Need to cancel BackgroundWorker Pin
Gerry Schmitz6-Sep-16 10:25
mveGerry Schmitz6-Sep-16 10:25 
QuestionFacebook login form Pin
Launchar31-Aug-16 18:14
Launchar31-Aug-16 18:14 
AnswerRe: Facebook login form Pin
Mycroft Holmes31-Aug-16 19:38
professionalMycroft Holmes31-Aug-16 19:38 
AnswerRe: Facebook login form Pin
Nathan Minier1-Sep-16 0:59
professionalNathan Minier1-Sep-16 0:59 
QuestionPRINT DATE TIME & TEXT ON PICTUREBOX Pin
Member 1271206730-Aug-16 18:11
Member 1271206730-Aug-16 18:11 
AnswerRe: PRINT DATE TIME & TEXT ON PICTUREBOX Pin
Mycroft Holmes30-Aug-16 20:17
professionalMycroft Holmes30-Aug-16 20:17 
QuestionGet value from string and pass it to another field Pin
Member 1105143930-Aug-16 11:50
Member 1105143930-Aug-16 11:50 

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.