public async Task ReceiveLoop() { await Task.Delay(0); Print.AsInfo("SocketLoad server started."); var data = new List <byte>(); server.Listen(100); var end = Task.Run(() => Console.ReadLine()); Print.AsWarn("The server will listen indefinitely, press <Enter> to stop accepting clients and quit."); while (true) { var accept = server.AcceptAsync(); accept.ConfigureAwait(false); if (Task.WaitAny(end, accept) == 1) { var client = accept.Result; new Task(() => Process(AllocType.Heap, client, (len) => Print.AsSuccess( "{0} bytes received from {1}.", len, ((IPEndPoint)client.RemoteEndPoint).Port.ToString())).Wait() ).Start(); } else { break; } } }
public async Task Start(IDictionary <string, List <string> > args) { await Task.Delay(0); var ms = new HighwaySettings(1024); // so that no refs are held ms.RegisterForProcessExitCleanup = false; // The unmanaged resource var MMF_FileID = string.Empty; // Must be in a separate non-async function so that no refs are holding it. void fin() { // Create without 'using' and forget to dispose var mmh = new MappedHighway(ms, 1024); MMF_FileID = mmh[0].FileID; mmh.Alloc(100); } fin(); GC.Collect(2); Thread.Sleep(5000); if (!File.Exists(MMF_FileID)) { Print.AsSuccess($"MappedHighway: the underlying file {MMF_FileID} was cleaned up by the finalizer."); Passed = true; } else { Print.AsTestFailure("MappedHighway: the finalizer was not triggered or the file deletion failed."); Passed = false; } IsComplete = true; }