示例#1
0
        private void Start()
        {
            int    threadCount, sessionSize, iterationsPerSession;
            string errMsg;

            if (!Int32.TryParse(tbThreadNum.Text, out threadCount))
            {
                MessageBox.Show("Invalid # of Threads", "Session Store Demo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (!Int32.TryParse(tbSessionSize.Text, out sessionSize))
            {
                MessageBox.Show("Invalid Session Size", "Session Store Demo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (!Int32.TryParse(tbNumIterations.Text, out iterationsPerSession))
            {
                MessageBox.Show("Invalid # of Iterations per Session", "Session Store Demo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (String.IsNullOrEmpty(tbConnectionString.Text))
            {
                MessageBox.Show("Please specify connection string", "Session Store Demo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            _connManager.ConnStr = tbConnectionString.Text;
            if (!_connManager.ValidateConnection(out errMsg))
            {
                MessageBox.Show(
                    String.Format("Cannot validate database connection. Error: {0}", errMsg),
                    "Session Store Demo", MessageBoxButtons.OK, MessageBoxIcon.Error
                    );
                return;
            }

            /* 7,800-byte threshold helps to address binary serialization overhead. That overhead depends on the types of the object properties. In real application
             * it is better to analyze the size of serialized object if you want to use different SPs for 1 and multiple data chunks */
            if (sessionSize > 7800 && cbUseTVP.Checked)
            {
                MessageBox.Show("Session objects require TVP due to their size", "Session Store Demo", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            _threads = new List <BaseThread>(threadCount);
            for (int i = 0; i < threadCount; i++)
            {
                _threads.Add(new WorkerThread(_connManager, cbUseInMemoryOLTP.Checked, cbUseTVP.Checked, sessionSize, iterationsPerSession));
            }
            foreach (WorkerThread thread in _threads)
            {
                thread.Start();
            }
            _statThread = new SessionStoreStatThread(5000, _threads, this);
            _statThread.Start();
            btnStart.Enabled = false;
            btnStop.Enabled  = true;
        }
        private void Start()
        {
            int    threadCount, sessionSize, iterationsPerSession;
            string errMsg;

            if (!Int32.TryParse(tbThreadNum.Text, out threadCount))
            {
                MessageBox.Show("Invalid # of Threads", "Session Store Demo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (!Int32.TryParse(tbSessionSize.Text, out sessionSize))
            {
                MessageBox.Show("Invalid Session Size", "Session Store Demo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (!Int32.TryParse(tbNumIterations.Text, out iterationsPerSession))
            {
                MessageBox.Show("Invalid # of Iterations per Session", "Session Store Demo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (String.IsNullOrEmpty(tbConnectionString.Text))
            {
                MessageBox.Show("Please specify connection string", "Session Store Demo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            _connManager.ConnStr = tbConnectionString.Text;
            if (!_connManager.ValidateConnection(out errMsg))
            {
                MessageBox.Show(
                    String.Format("Cannot validate database connection. Error: {0}", errMsg),
                    "Session Store Demo", MessageBoxButtons.OK, MessageBoxIcon.Error
                    );
                return;
            }
            _threads = new List <BaseThread>(threadCount);
            for (int i = 0; i < threadCount; i++)
            {
                _threads.Add(new WorkerThread(_connManager, cbUseInMemoryOLTP.Checked, sessionSize, iterationsPerSession));
            }
            foreach (WorkerThread thread in _threads)
            {
                thread.Start();
            }
            _statThread = new SessionStoreStatThread(5000, _threads, this);
            _statThread.Start();
            btnStart.Enabled = false;
            btnStop.Enabled  = true;
        }