Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ BeginWriteInternal()

Task System.IO.Stream.BeginWriteInternal ( byte[] buffer,
int offset,
int count,
AsyncCallback callback,
object state,
bool serializeAsynchronously,
bool apm )
inlinepackageinherited

Definition at line 818 of file Stream.cs.

819 {
821 if (!CanWrite)
822 {
823 ThrowHelper.ThrowNotSupportedException_UnwritableStream();
824 }
826 Task task = null;
827 if (serializeAsynchronously)
828 {
829 task = semaphoreSlim.WaitAsync();
830 }
831 else
832 {
833 semaphoreSlim.Wait();
834 }
835 ReadWriteTask readWriteTask = new ReadWriteTask(isRead: false, apm, delegate
836 {
837 ReadWriteTask readWriteTask2 = Task.InternalCurrent as ReadWriteTask;
838 try
839 {
840 readWriteTask2._stream.Write(readWriteTask2._buffer, readWriteTask2._offset, readWriteTask2._count);
841 return 0;
842 }
843 finally
844 {
845 if (!readWriteTask2._apm)
846 {
847 readWriteTask2._stream.FinishTrackingAsyncOperation(readWriteTask2);
848 }
849 readWriteTask2.ClearBeginState();
850 }
851 }, state, this, buffer, offset, count, callback);
852 if (task != null)
853 {
854 RunReadWriteTaskWhenReady(task, readWriteTask);
855 }
856 else
857 {
858 RunReadWriteTask(readWriteTask);
859 }
860 return readWriteTask;
861 }
static void ValidateBufferArguments(byte[] buffer, int offset, int count)
Definition Stream.cs:1044
static void RunReadWriteTask(ReadWriteTask readWriteTask)
Definition Stream.cs:877
static void RunReadWriteTaskWhenReady(Task asyncWaiter, ReadWriteTask readWriteTask)
Definition Stream.cs:863
SemaphoreSlim EnsureAsyncActiveSemaphoreInitialized()
Definition Stream.cs:535

References System.IO.Stream.ReadWriteTask._apm, System.IO.Stream.ReadWriteTask._buffer, System.IO.Stream.ReadWriteTask._count, System.IO.Stream.ReadWriteTask._offset, System.IO.Stream.ReadWriteTask._stream, System.buffer, System.IO.Stream.CanWrite, System.IO.Stream.ReadWriteTask.ClearBeginState(), System.count, System.IO.Stream.EnsureAsyncActiveSemaphoreInitialized(), System.IO.Stream.FinishTrackingAsyncOperation(), System.offset, System.IO.Stream.RunReadWriteTask(), System.IO.Stream.RunReadWriteTaskWhenReady(), System.state, System.task, System.ThrowHelper.ThrowNotSupportedException_UnwritableStream(), System.IO.Stream.ValidateBufferArguments(), System.Threading.SemaphoreSlim.Wait(), System.Threading.SemaphoreSlim.WaitAsync(), and System.IO.Stream.Write().

Referenced by System.IO.Stream.BeginEndWriteAsync(), System.IO.Stream.SyncStream.BeginWrite(), System.IO.Stream.BeginWrite(), System.IO.Strategies.Net5CompatFileStreamStrategy.WriteAsync(), and System.IO.Strategies.Net5CompatFileStreamStrategy.WriteAsync().