Example #1
0
        /// <summary>
        /// https://stackoverflow.com/questions/661561/how-to-update-the-gui-from-another-thread-in-c
        /// </summary>
        /// <param name="progress"></param>
        /// <param name="SessionName"></param>
        /// <param name="sqlCSB"></param>
        public void ReadEventStream(IProgress <string> progress, string SessionName,
                                    SqlConnectionStringBuilder sqlCSB)
        {
            cancelProcessing = false;

            using (QueryableXEventData xEvents = new QueryableXEventData(
                       sqlCSB.ConnectionString,
                       SessionName,
                       EventStreamSourceOptions.EventStream,
                       EventStreamCacheOptions.DoNotCache))
            {
                foreach (PublishedEvent xEvent in xEvents)
                {
                    if (cancelProcessing)
                    {
                        //progress.Report("xEvents.Dispose();" + Environment.NewLine);
                        xEvents.Dispose();
                        break;
                    }
                    else
                    {
                        if (eventsHandled.Contains(xEvent.Name))
                        {
                            progress.Report(xEvent.Name);
                            responseOpts.Respond(xEvent);
                        }
                    }
                }
            }
        }
Example #2
0
        private void KeepRunningChecker(object stateInfo)
        {
            if (Monitor.TryEnter(_keepRunningLocker) && !_StopRequested)
            {
                SqlConnection MonConn = null;
                try
                {
                    MonConn = new SqlConnection(_MonServerWriteConnectionString);
                    MonConn.Open();
                    SqlCommand GetServersToTrace = MonConn.CreateCommand();
                    GetServersToTrace.CommandType = CommandType.StoredProcedure;
                    GetServersToTrace.CommandText = "GetServersToTrace";
                    SqlParameter server_name = new SqlParameter("@server_name", SqlDbType.VarChar);
                    GetServersToTrace.Parameters.Add(server_name);
                    server_name.Value = _serverName;

                    SqlParameter session_name = new SqlParameter("@session_name", SqlDbType.VarChar);
                    GetServersToTrace.Parameters.Add(session_name);
                    session_name.Value = _sessionName;

                    SqlParameter last_event_count = new SqlParameter("@last_event_count", SqlDbType.VarChar);
                    GetServersToTrace.Parameters.Add(last_event_count);
                    last_event_count.Value = _CapturesInTheLastSecond;

                    SqlParameter last_valid_event_count = new SqlParameter("@last_valid_event_count", SqlDbType.VarChar);
                    GetServersToTrace.Parameters.Add(last_valid_event_count);
                    last_valid_event_count.Value = _ValidCapturesInTheLastSecond;

                    using (SqlDataReader reader = GetServersToTrace.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            if (!Convert.ToBoolean(reader["active"]))
                            {
                                _CapturesInTheLastSecond      = 0; /* reset to capture count */
                                _ValidCapturesInTheLastSecond = 0; /* reset to capture count */
                                _KeepRunningTimer.Dispose();
                                _StopRequested = true;
                                if (_xEventDataStream != null)
                                {
                                    eQueue.UnsubscribeFromEventStream(this); /* unsubscribe the queued inserter */
                                    _xEventDataStream.Dispose();             /* reset the stream to force exit */
                                }
                            }
                        }
                    }

                    _CapturesInTheLastSecond      = 0; /* reset to capture count */
                    _ValidCapturesInTheLastSecond = 0; /* reset to capture count */
                }
                catch (Exception xyz)
                {
                    Console.WriteLine("Fatal error checking if capture should stop" + xyz.ToString());
                }
                finally
                {
                    MonConn.Close();
                    Monitor.Exit(_keepRunningLocker);
                }
            }
        }