private Task StartCommitTask( BlockingCollection <QueuedMemoryWriter> threadWriter, SequentialFileWriterStream data, SequentialFileWriterStream index ) { #pragma warning disable CA2008 // Do not create tasks without passing a TaskScheduler * var commitTask = Task.Factory.StartNew( () => { while (!threadWriter.IsCompleted) { QueuedMemoryWriter writer; try { writer = threadWriter.Take(); } catch (InvalidOperationException) { // Per MSDN, it's fine if we're here, successful completion of adding can rarely put us into this state. break; } writer.CommitTo(data, index); } } ); #pragma warning restore CA2008 // Do not create tasks without passing a TaskScheduler * return(commitTask); }
private void WriteCount(SequentialFileWriterStream indexFile, int count) { var buffer = new byte[4]; buffer[0] = (byte)count; buffer[1] = (byte)(count >> 8); buffer[2] = (byte)(count >> 16); buffer[3] = (byte)(count >> 24); indexFile.Write(buffer, 0, buffer.Length); }
private void OpenFiles() { itemData = new SequentialFileWriterStream(World.ItemDataPath); itemIndex = new SequentialFileWriterStream(World.ItemIndexPath); mobileData = new SequentialFileWriterStream(World.MobileDataPath); mobileIndex = new SequentialFileWriterStream(World.MobileIndexPath); guildData = new SequentialFileWriterStream(World.GuildDataPath); guildIndex = new SequentialFileWriterStream(World.GuildIndexPath); WriteCount(itemIndex, World.Items.Count); WriteCount(mobileIndex, World.Mobiles.Count); WriteCount(guildIndex, BaseGuild.List.Count); }