Skip to content

Instantly share code, notes, and snippets.

@gluschenko
Created April 24, 2016 11:31
Show Gist options
  • Save gluschenko/feb701305a265b0dfb422c73e7ca098c to your computer and use it in GitHub Desktop.
Save gluschenko/feb701305a265b0dfb422c73e7ca098c to your computer and use it in GitHub Desktop.
Small queue system
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TestTestTest
{
class Program
{
static Queue Users = new Queue();
static Queue Photos = new Queue();
static void Main(string[] args)
{
Users.Push((int)1);
while (true)
{
System.Threading.Thread.Sleep(1);
Execute();
}
}
static bool isON = true;
static void Execute()
{
object o = Users.Pop();
if (o != null) InvokeMethod((int)o + 1, (n) => {
Console.WriteLine(o.ToString() + " - " + Users.Objects.Count);
Users.Kill();
for (int i = 0; i < 10; i++ )
{
if (Users.Objects.Count > 10000) isON = false;
if (isON) Users.Push(Users.Objects.Count);
}
});
}
static void InvokeMethod(int next, Action<int> Done)
{
Done(next);
}
}
public class Queue {
public List<object> Objects;
public Queue()
{
Objects = new List<object>();
}
public void Push(object o)
{
Objects.Add(o);
}
public object Pop()
{
if (Objects.Count > 0) return Objects[0];
return null;
}
public void Kill()
{
if (Objects.Count > 0) Objects.RemoveAt(0);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment