Example #1
0
 /// <summary></summary>
 public void Clear()
 {
     lock (_Locker)
     {
         _Queue.Clear();
     }
 }
Example #2
0
 public bool TryRemove(T item, int timeout = System.Threading.Timeout.Infinite)
 {
     if (Monitor.TryEnter(q, timeout))
     {
         try
         {
             var items = q.ToArray();
             if (!items.Any(x => !x.Equals(item)))
             {
                 return(false);
             }
             q.Clear();
             foreach (var i in items.Where(x => !x.Equals(item)))
             {
                 q.Enqueue(i);
             }
             return(true);
         }
         catch { return(false); }
         finally { Monitor.Exit(q); }
     }
     else
     {
         return(false);
     }
 }
Example #3
0
 /// <summary>
 /// Clears queue.
 /// </summary>
 public void Clear()
 {
     lock (this)
     {
         dataQueue.Clear();
         queueHasData.Reset();
     }
 }
Example #4
0
 /// <summary>
 /// Cancels the processing of the current enumerator, and all future
 /// ones.
 /// </summary>
 public override void CancelExtensions( )
 {
     lock ( _lock )
     {
         current = null;
         extensions.Clear();
     }
 }
Example #5
0
 private void ClearQueue(bool sent)
 {
     mQueue.Clear();
     mPending.Clear();
     if (sent)
     {
         mSent.Clear();
     }
 }
Example #6
0
 private void ClearQueue(bool sent)
 {
     mQueue.Clear();
     mPending.Clear();
     if (sent)
     {
         mSent.Clear();
     }
     mRetryQueue = null;
 }
Example #7
0
        static StackObject *Clear_1(ILIntepreter __intp, StackObject *__esp, IList <object> __mStack, CLRMethod __method, bool isNewObj)
        {
            ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
            StackObject *ptr_of_this_method;
            StackObject *__ret = ILIntepreter.Minus(__esp, 1);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
            System.Collections.Generic.Queue <System.ValueTuple <System.Int32, System.Int64, System.Int32> > instance_of_this_method = (System.Collections.Generic.Queue <System.ValueTuple <System.Int32, System.Int64, System.Int32> >) typeof(System.Collections.Generic.Queue <System.ValueTuple <System.Int32, System.Int64, System.Int32> >).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack), (CLR.Utils.Extensions.TypeFlags) 0);
            __intp.Free(ptr_of_this_method);

            instance_of_this_method.Clear();

            return(__ret);
        }
Example #8
0
        static StackObject *Clear_3(ILIntepreter __intp, StackObject *__esp, IList <object> __mStack, CLRMethod __method, bool isNewObj)
        {
            ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
            StackObject *ptr_of_this_method;
            StackObject *__ret = ILIntepreter.Minus(__esp, 1);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
            System.Collections.Generic.Queue <System.String> instance_of_this_method = (System.Collections.Generic.Queue <System.String>) typeof(System.Collections.Generic.Queue <System.String>).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
            __intp.Free(ptr_of_this_method);

            instance_of_this_method.Clear();

            return(__ret);
        }
Example #9
0
        public static void Demo()
        {
            Console.WriteLine("Queue......");

            System.Collections.Generic.Queue <string> movies = new System.Collections.Generic.Queue <string>();
            movies.Enqueue("Ace Ventura");
            movies.Enqueue("Batman");
            movies.Enqueue("Cable Guy");
            movies.Enqueue("Dallas Buyers Club");
            movies.Enqueue("East of Eden");

            Console.WriteLine("Default content of Queue");

            foreach (string movie in movies)
            {
                Console.WriteLine(movie);
            }

            Console.WriteLine("\nDequeuing '{0}'", movies.Dequeue());
            Console.WriteLine("The next item to dequeue using peek: {0}", movies.Peek());
            Console.WriteLine("Dequeuing '{0}'", movies.Dequeue());

            System.Collections.Generic.Queue <string> queueCopy = new System.Collections.Generic.Queue <string>(movies.ToArray());

            Console.WriteLine("\nContents of the first copy:");
            foreach (string movie in queueCopy)
            {
                Console.WriteLine(movie);
            }

            string[] array2 = new string[movies.Count * 2];
            movies.CopyTo(array2, movies.Count);

            System.Collections.Generic.Queue <string> queueCopy2 = new System.Collections.Generic.Queue <string>(array2);

            Console.WriteLine("\nContents of the second copy, with duplicates and" + " nulls:");
            foreach (string movie in queueCopy2)
            {
                Console.WriteLine(movie);
            }

            Console.WriteLine("\nqueueCopy.Contains(\"Dallas Buyers Club\") = {0}", queueCopy.Contains("Dallas Buyers Club"));

            Console.WriteLine("\nqueueCopy.Clear()");
            queueCopy.Clear();
            Console.WriteLine("\nqueueCopy.Count = {0}", queueCopy.Count);

            Console.WriteLine("End of Queue");
        }
    public bool TryGet(out T[] items)
    {
        if (_queue.Count > 0)
        {
            lock (_lock)
            {
                if (_queue.Count > 0)
                {
                    items = _queue.ToArray();
                    _queue.Clear();
                    return(true);
                }
            }
        }

        items = null;
        return(false);
    }
Example #11
0
        public static void CommitToStore(System.Collections.Generic.Queue <LogEntry> traceQueue, int incidentId)
        {
            LogEntry[] queueToWrite = traceQueue.ToArray();

            traceQueue.Clear();

            foreach (LogEntry traceEntry in queueToWrite)
            {
                traceEntry.Win32ThreadId = incidentId.ToString();

                if (traceEntry.Message.Length > 20000)
                {
                    traceEntry.Message = traceEntry.Message.Substring(0, 20000);
                }

                Logger.Write(traceEntry);
            }
        }
Example #12
0
        public T[] DequeueAll()
        {
            bool gotLock = false;

            T[] all;

            try
            {
                _Lock.Enter(ref gotLock);
                all = _Set.ToArray();
                _Set.Clear();
            }
            finally
            {
                if (gotLock)
                {
                    _Lock.Exit();
                }
            }
            return(all);
        }
Example #13
0
        }     // End Sub Main

        private static void HandleMessage()
        {
            while (true)
            {
                MessageTrigger.WaitOne(5000);    // A 5000ms timeout to force processing
                string[] messages = null;
                lock (Messages)
                {
                    messages = Messages.ToArray();
                    Messages.Clear();
                }

                foreach (string msg in messages)
                {
                    // Write message to file...
                    // WriteToCSV(msg);

                    // Test msg for conditions and send email if needed
                    // if (...) { SendEmail(msg); }
                }
            } // Whend
        }     // End Sub HandleMessage
Example #14
0
        public void ReferenceQueueStory()
        {
            var que = new System.Collections.Generic.Queue <string>();

            que.Enqueue("foo");
            que.Count.ShouldEqual(1);
            que.Peek().ShouldEqual("foo");
            que.Dequeue().ShouldEqual("foo");
            que.Count.ShouldEqual(0);

            que.Enqueue("foo");
            que.Enqueue("bar");
            que.Count.ShouldEqual(2);
            que.Peek().ShouldEqual("foo");
            que.Dequeue().ShouldEqual("foo");
            que.Dequeue().ShouldEqual("bar");
            que.Count.ShouldEqual(0);

            que.Enqueue("foo");
            que.Enqueue("bar");
            que.Enqueue("baz");
            que.Clear();
            que.ShouldBeEmpty();
        }
Example #15
0
 public void Clear()
 {
     innerQueue.Clear();
 }
Example #16
0
 public void Clear() => queue.Clear();
Example #17
0
        public void ReferenceQueueStory()
        {
            var que = new System.Collections.Generic.Queue<string>();

            que.Enqueue("foo");
            que.Count.ShouldEqual(1);
            que.Peek().ShouldEqual("foo");
            que.Dequeue().ShouldEqual("foo");
            que.Count.ShouldEqual(0);

            que.Enqueue("foo");
            que.Enqueue("bar");
            que.Count.ShouldEqual(2);
            que.Peek().ShouldEqual("foo");
            que.Dequeue().ShouldEqual("foo");
            que.Dequeue().ShouldEqual("bar");
            que.Count.ShouldEqual(0);

            que.Enqueue("foo");
            que.Enqueue("bar");
            que.Enqueue("baz");
            que.Clear();
            que.ShouldBeEmpty();
        }
Example #18
0
        public void sendingThread()
        {
            NetworkMessage nm;

            while (!killThread)
            {
                lock (messageQueue)
                {
                    if (messageQueue.Count > 0)
                    {
                        nm = messageQueue.Dequeue();
                    }
                    else
                    {
                        nm = null;
                    }
                }
                if (nm != null)
                {
                    if (nm.NetworkProtocol == Protocol.TCP)                 //sending message via TCP
                    {
                        //Debug.WriteLine("Sending event message via TCP");
                        try
                        {
                            sbyte [] message = nm.Message();
                            byte[]   payload = new byte[message.Length];
                            for (int i = 0; i < message.Length; i++)
                            {
                                payload[i] = (byte)message[i];
                            }
                            tcptoBeSent.SetBuffer(payload, 0, payload.Length);
                            ServersStorage.ServerSocket.SendAsync(tcptoBeSent);
                        }
                        catch
                        {
                            Debug.WriteLine("Sending failed");
                            lock (messageQueue)
                            {
                                messageQueue.Clear();
                            }
                        }
                    }
                    else                                            //sending message via UDP
                    {
                        //Debug.WriteLine("Sending event message via UDP");

                        SocketAsyncEventArgs socketEventArg = new SocketAsyncEventArgs();

                        socketEventArg.RemoteEndPoint = new DnsEndPoint(ServersStorage.SelectedServer.Address, ServersStorage.SelectedServer.Port);
                        //ManualResetEvent _clientDone = new ManualResetEvent(false);
                        sbyte[] message = nm.Message();
                        byte[]  payload = new byte[message.Length];
                        for (int i = 0; i < message.Length; i++)
                        {
                            payload[i] = (byte)message[i];
                        }
                        socketEventArg.SetBuffer(payload, 0, payload.Length);
                        //_clientDone.Reset();
                        udpsocket.SendToAsync(socketEventArg);
                    }
                }
            }
        }
Example #19
0
        /// <summary>
        /// Write the supplied message to the queue. Will trigger WriteToStore if message level matches configured logging level
        /// </summary>
        /// <param name="message">Trace message</param>
        /// <param name="callingMethodName">Name of the calling method</param>
        /// <param name="messageLevel">Require tracing level</param>
        public static void Write(string message, string callingMethodName, TraceLevel messageLevel)
        {
            try
            {
                // Stop immediately if logging is disabled.
                if (loggingLevel == TraceLevel.Off)
                {
                    return;
                }

                LogEntry logEntry = new LogEntry();
                logEntry.Message = message;

                // Store the calling method's name as an extended property
                logEntry.ExtendedProperties.Add("MethodName", callingMethodName);
                logEntry.Category = messageLevel.ToString();//category in log table, also determines log distribution

                // Translate from TraceLevel to Severity
                switch (messageLevel)
                {
                case TraceLevel.Error:
                    logEntry.Severity = Severity.Error;
                    break;

                case TraceLevel.Warning:
                    logEntry.Severity = Severity.Warning;
                    break;

                default:
                    logEntry.Severity = Severity.Information;
                    break;
                }

                // Check whether the supplied message level is currently being logged.
                if (messageLevel <= loggingLevel)
                {
                    //write log entries from the queue first, then the current entry
                    if (traceQueueSize > 0)
                    {
                        traceQueue.Enqueue(logEntry);

                        if (CommitToStore != null)
                        {
                            CommitToStore(traceQueue, incidentId);
                            traceQueue.Clear();
                        }
                    }
                    // Writes the log entry.
                }
                else
                {//keep message in queue and only write if there is a logged message with a severity matching the configured traceLevel
                    if (traceQueueSize > 0)
                    {
                        if (traceQueue.Count >= traceQueueSize)
                        {
                            traceQueue.Dequeue();
                        }

                        traceQueue.Enqueue(logEntry);
                    }
                }
            }
            catch
            {
                loggingLevel = TraceLevel.Off;
                throw;
            }
        }