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

◆ BeginReadInternal()

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

Definition at line 693 of file Stream.cs.

694 {
696 if (!CanRead)
697 {
698 ThrowHelper.ThrowNotSupportedException_UnreadableStream();
699 }
701 Task task = null;
702 if (serializeAsynchronously)
703 {
704 task = semaphoreSlim.WaitAsync();
705 }
706 else
707 {
708 semaphoreSlim.Wait();
709 }
710 ReadWriteTask readWriteTask = new ReadWriteTask(isRead: true, apm, delegate
711 {
712 ReadWriteTask readWriteTask2 = Task.InternalCurrent as ReadWriteTask;
713 try
714 {
715 return readWriteTask2._stream.Read(readWriteTask2._buffer, readWriteTask2._offset, readWriteTask2._count);
716 }
717 finally
718 {
719 if (!readWriteTask2._apm)
720 {
721 readWriteTask2._stream.FinishTrackingAsyncOperation(readWriteTask2);
722 }
723 readWriteTask2.ClearBeginState();
724 }
725 }, state, this, buffer, offset, count, callback);
726 if (task != null)
727 {
728 RunReadWriteTaskWhenReady(task, readWriteTask);
729 }
730 else
731 {
732 RunReadWriteTask(readWriteTask);
733 }
734 return readWriteTask;
735 }
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.CanRead, System.IO.Stream.ReadWriteTask.ClearBeginState(), System.count, System.IO.Stream.EnsureAsyncActiveSemaphoreInitialized(), System.IO.Stream.FinishTrackingAsyncOperation(), System.offset, System.IO.Stream.Read(), System.IO.Stream.RunReadWriteTask(), System.IO.Stream.RunReadWriteTaskWhenReady(), System.state, System.task, System.ThrowHelper.ThrowNotSupportedException_UnreadableStream(), System.IO.Stream.ValidateBufferArguments(), System.Threading.SemaphoreSlim.Wait(), and System.Threading.SemaphoreSlim.WaitAsync().

Referenced by System.IO.Stream.BeginEndReadAsync(), System.IO.Stream.SyncStream.BeginRead(), System.IO.Stream.BeginRead(), System.IO.Strategies.Net5CompatFileStreamStrategy.ReadAsync(), and System.IO.Strategies.Net5CompatFileStreamStrategy.ReadAsync().