void StreamField(NetworkStream stream) { if (stream == null) { return; } ClientThreads.AddHandler(this.ID, wh); bool isAlive = true; int[] cells; byte[] data; while (isAlive) { wh.WaitOne(); cells = ThreadMaster.ClientGetCells(); // sending metadata data = new byte[sizeof(int)]; Buffer.BlockCopy(new int[] { cells.Length }, 0, data, 0, data.Length); stream.Write(data, 0, data.Length); // sending data data = new byte[cells.Length * sizeof(int)]; Buffer.BlockCopy(cells, 0, data, 0, data.Length); stream.Write(data, 0, data.Length); } }
static void Live() { while (true) { generation++; lock (lifeLocker){ life.IterateOnce(); } lock (lifeLocker) // lifeLocker --> _Life.cs { lock (localCellMapLocker) { life.GetCellMap(ref localCellMap); } } ClientThreads.StartEveryone(); Thread.Sleep(msPerFrame); } }