static void Main(string[] args) { clientId = IDGenerator.Generate(); isRunning = true; ENet.Library.Initialize(); Thread connectionLoop = new Thread(new ThreadStart(ConnectionLoop)); Thread receiveQueue = new Thread(new ThreadStart(ReceiveProcess)); connectionLoop.Start(); receiveQueue.Start(); while (isRunning) { Console.WriteLine("Accepting input"); string input = Console.ReadLine(); Send(new Tuple <Data, Peer>(new Data() { command = Command.MOVEMENT_UPDATE, content = input, clientId = clientId }, peer)); } Thread.Sleep(1000); /* * for(int i = 0; i < 20; i++){ * Send(new Tuple<Data, Peer>(new Data(){command = Command.TEST_MESSAGE, content = "Message " + i, clientId = clientId}, peer)); * } */ }
public void Start() { clientId = IDGenerator.Generate(); player.name = clientId; isRunning = true; Thread connectionLoop = new Thread(new ThreadStart(ConnectionLoop)); Thread receiveQueue = new Thread(new ThreadStart(ReceiveProcess)); Debug.Log("Starting threads"); connectionLoop.Start(); receiveQueue.Start(); }
public string GenerateId(RcFile aSelectedRcFile, IEnumerable <RcFile> aRcFiles, bool aUniquePerProject) { List <string> rcPaths = (from rcFile in aRcFiles where rcFile.Project.ProjectName == aSelectedRcFile.Project.ProjectName select rcFile.FilePath).ToList(); IDGenerator idGenerator = new IDGenerator(); if (aUniquePerProject) { return(idGenerator.GenerateUniquePerProject(rcPaths).ToString()); } else { return(mIDGenerator.Generate().ToString()); } }
public static void DoTimeTest() { UtilityRandom random = new UtilityRandom(); random.Next(); IDGenerator geanIdg = new IDGenerator(); geanIdg.Generate(); int count = 500 * 10000; Stopwatch sw = new Stopwatch(); Console.WriteLine("Start......"); //Gean.Data的Id生成器----------------------- long geanIdTime; sw.Reset(); sw.Start(); for (int i = 0; i < count; i++) { string id = geanIdg.Generate(); } sw.Stop(); geanIdTime = sw.ElapsedMilliseconds; //随机数字----------------------- long randNumTime; sw.Reset(); sw.Start(); for (int i = 0; i < count; i++) { string id = random.Next(1, count).ToString(); } sw.Stop(); randNumTime = sw.ElapsedMilliseconds; //随机4位小写字母----------------------- long randTime; sw.Reset(); sw.Start(); for (int i = 0; i < count; i++) { string id = random.GetString(4, UtilityRandom.RandomCharType.Lowercased); } sw.Stop(); randTime = sw.ElapsedMilliseconds; //数字累计----------------------- long gerTime; sw.Reset(); sw.Start(); for (int i = 0; i < count; i++) { string id = (i + i + i).ToString(); } sw.Stop(); gerTime = sw.ElapsedMilliseconds; //IDGenerator生成----------------------- long idgTime; sw.Reset(); sw.Start(); UUIDGenerator idg = new UUIDGenerator(); for (int i = 0; i < count; i++) { string id = idg.Generate(); } sw.Stop(); idgTime = sw.ElapsedMilliseconds; //Guid----------------------- long guidTime; sw.Reset(); sw.Start(); for (int i = 0; i < count; i++) { string id = Guid.NewGuid().ToString(); } sw.Stop(); guidTime = sw.ElapsedMilliseconds; Console.WriteLine("Gean.Data的Id生成器: " + geanIdTime.ToString() + Sudu(geanIdTime, count)); Console.WriteLine("随机数字: " + randNumTime.ToString() + Sudu(randNumTime, count)); Console.WriteLine("随机4位小写字母: " + randTime.ToString() + Sudu(randTime, count)); Console.WriteLine("数字累计: " + gerTime.ToString() + Sudu(gerTime, count)); Console.WriteLine("IDGenerator生成: " + idgTime.ToString() + Sudu(idgTime, count)); Console.WriteLine("Guid: " + guidTime.ToString() + Sudu(guidTime, count)); }
/// <summary> /// Generates a unique identifier. /// </summary> /// <returns></returns> public static long GenerateGuid() { return(IDGenerator.Generate()); }