Example #1
0
        private static void QueueProcessorStart(Queue <Package> queue, object syncLock)
        {
            try
            {
                List <byte[]> packageBinaryList = new List <byte[]>();

                System.Timers.Timer         timer = new System.Timers.Timer();
                TaskCompletionSource <bool> tcs   = new TaskCompletionSource <bool>();
                timer.Interval  = 200;
                timer.AutoReset = true;
                timer.Elapsed  += (obj, args) =>
                {
                    Package package = null;

                    lock (syncLock)
                    {
                        if (queue.Any())
                        {
                            package = queue.Dequeue();
                        }
                    }

                    if (package != null)
                    {
                        //PackageManager.PackageManager pm = new PackageManager.PackageManager(new JsonNet(), new GZipStreamCompression());
                        //byte[] packageBinary = pm.ToBinaryFormat(package);
                        //packageBinaryList.Add(packageBinary);

                        DataRouter.Route(package);
                    }

                    tcs.TrySetResult(true);
                };

                timer.Start();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }