Code: Select all
	class MyConnection: IDisposable
        {
            private OracleConnection Connection { get; set; }
            public MyConnection(string connectionString)
            {
                Connection = new OracleConnection(connectionString);
                Connection.Open();
            }
            public int ExecuteNonquery(string cmd)
            {
                var myCommand = new OracleCommand(cmd, Connection);
                return myCommand.ExecuteNonQuery();
            }
            public void Dispose()
            {
                Connection.Close();
            }
        }
        private void Start()
        {
            var cb = new OracleConnectionStringBuilder();
            cb.ConnectionTimeout = 30;
            cb.DefaultCommandTimeout = 30;
            cb.MaxPoolSize = 100;
            cb.Pooling = false;
            cb.UserId = "tst";
            cb.Password = "tst";
            cb.Server = "srv1";
            cb.ValidateConnection = true;
            var workedThread1 = new Thread(new ParameterizedThreadStart(DoWork1)) { IsBackground = true };
            workedThread1.Start(cb.ToString());
            var workedThread2 = new Thread(new ParameterizedThreadStart(DoWork2)) { IsBackground = true };
            workedThread2.Start(cb.ToString());
            Thread.Sleep(5000);
            workedThread1.Abort();
        }
        private void DoWork1(object connectionString)
        {
            try
            {
                Debug.WriteLine("Thread1 started");
                while (true)
                {
                    using (var connection = new MyConnection((string)connectionString))
                    {
// [b]ROW IS LOCKED IN OTHER PROGRAM[/b]
                        connection.ExecuteNonquery("UPDATE test SET name = '11111' where id = 1");
                    }
                    Debug.WriteLine("Update row");
                    Thread.Sleep(1000);
                }
            }catch(ThreadAbortException e)
            {
                Debug.WriteLine("ThreadAbortException: Thread 1");
            }
        }
        private void DoWork2(object connectionString)
        {
            Debug.WriteLine("Thread2 started");
            while (true)
            {
                using (var connection = new MyConnection((string)connectionString))
                {
                    connection.ExecuteNonquery("SELECT 1 FROM dual");
                }
                Debug.WriteLine("Test Query");
                Thread.Sleep(1000);
            }
        }
Thread1 started
Thread2 started
The thread '' (0x3038) has exited with code 0 (0x0).
The thread '' (0x2ea8) has exited with code 0 (0x0).
The thread '' (0x2eb0) has exited with code 0 (0x0).
Test Query
The thread '' (0x319c) has exited with code 0 (0x0).
The thread '' (0x3234) has exited with code 0 (0x0).
Test Query
The thread '' (0x2dcc) has exited with code 0 (0x0).
The thread '' (0x1e30) has exited with code 0 (0x0).
Test Query
The thread '' (0x1d68) has exited with code 0 (0x0).
The thread '' (0x1f94) has exited with code 0 (0x0).
Test Query
The thread '' (0x18d0) has exited with code 0 (0x0).
The thread '' (0x2864) has exited with code 0 (0x0).
Test Query
A first chance exception of type 'System.Threading.ThreadAbortException' occurred in Devart.Data.dll
The thread '' (0x33e8) has exited with code 0 (0x0).
The thread '' (0x332c) has exited with code 0 (0x0).
Test Query
The thread '' (0x1f40) has exited with code 0 (0x0).
The thread '' (0x2d5c) has exited with code 0 (0x0).
Test Query
The thread '' (0x3764) has exited with code 0 (0x0).
The thread '' (0x3d10) has exited with code 0 (0x0).
Test Query
The thread '' (0x2ebc) has exited with code 0 (0x0).
The thread '' (0x312c) has exited with code 0 (0x0).
... working, but ThreadAbortException havn't been catched
Now enable pooling:
Code: Select all
            var cb = new OracleConnectionStringBuilder();
            cb.ConnectionTimeout = 30;
            cb.DefaultCommandTimeout = 30;
            cb.MaxPoolSize = 100;
            cb.Pooling = true;
            cb.UserId = "tst";
            cb.Password = "tst";
            cb.Server = "srv1";
            cb.ValidateConnection = true;
Thread2 started
Thread1 started
The thread '' (0x43d0) has exited with code 0 (0x0).
The thread '' (0x6b0) has exited with code 0 (0x0).
The thread '' (0x43d8) has exited with code 0 (0x0).
Test Query
The thread '' (0x322c) has exited with code 0 (0x0).
Test Query
The thread '' (0x3ac0) has exited with code 0 (0x0).
Test Query
The thread '' (0x43c0) has exited with code 0 (0x0).
Test Query
The thread '' (0x412c) has exited with code 0 (0x0).
Test Query
A first chance exception of type 'System.Threading.ThreadAbortException' occurred in Devart.Data.dll
ThreadAbortException: Thread 1
A first chance exception of type 'System.Threading.ThreadAbortException' occurred in TestConnection.exe
The thread '' (0x1ee8) has exited with code 0 (0x0).
The thread '' (0x404c) has exited with code 0 (0x0).
Test Query
ThreadAbortException is caught, but thread2 is locked, why?