Esempio n. 1
0
        public void BasicInsertSelectSynchronousCancel()
        {
            //Assume
            const string insertCql = @"insert into Test.BasicFlow (id,value) values (54235,'Hallo 54235');";
            const string retrieveCql = @"select * from Test.BasicFlow;";

            //Act
            using (var connection = new CqlConnection(ConnectionString))
            {
                connection.Open();

                //insert data
                var cmd = new CqlCommand(connection, insertCql, CqlConsistency.One);
                cmd.ExecuteNonQuery();


                //select data
                var selectCmd = new CqlCommand(connection, retrieveCql, CqlConsistency.One);
                selectCmd.CommandTimeout = Timeout.Infinite;
                selectCmd.Prepare();

                
                //get connection, and cancel the select as soon as it registers
                EventHandler<Network.LoadChangeEvent> cancelHandler = (src, ev) => selectCmd.Cancel();
                Connection networkConnection = connection.GetConnection();

                networkConnection.OnLoadChange += cancelHandler;

                try
                {
                    CqlDataReader reader = selectCmd.ExecuteReader();
                }
                finally
                {
                    networkConnection.OnLoadChange -= cancelHandler;
        }

            }
        }