Questions tagged [beginread]
27 questions
16
votes
2 answers
BeginReceive / BeginRead timeouts
I'm using a NetworkStream & TcpClient to asynchronously receive data using BeginRead. I need to apply a time-out to this operation, such that after a specified amount of time the read will be aborted.
As far as I'm able to tell, this isn't…

Barg
- 2,968
- 7
- 26
- 28
16
votes
1 answer
When using FileStream.ReadAsync() should I open the file in async mode?
The old .Net way of performing asynchronous I/O for a FileStream is to use FileStream.BeginRead() and FileStream.EndRead().
The MSDN documentation for FileStream.BeginRead() states:
FileStream provides two different modes of operation: synchronous…

Matthew Watson
- 104,400
- 10
- 158
- 276
5
votes
3 answers
Stop Stream.BeginRead()
i need to read data from my virtual com port and detect the message "Dreq". Once i press the connect button, it connects to my COM8 port and begins reading in a new thread. I also have a disconnect button in which i wish to close the reading and…

RStyle
- 111
- 2
- 6
5
votes
2 answers
Stopping an asynchronous stream outside of the AsyncCallback function
I've got a Stream object and I am using BeginRead to begin reading (obviously) into a buffer; the AsyncCallback function is called once the reading is complete. Within this function I can check if the user wants to get the next 'block' and start the…

R4D4
- 1,382
- 2
- 13
- 34
5
votes
1 answer
TcpClient; NetworkStream; ReadAsync; C#
Please excuse my lack of knowledge regarding Tasks and Async.
Using the TcpClient class I am creating a connection with an available server:
void async RunClientAsync()
{
TcpClient client = new TcpClient();
try
{
await…

Jam
- 53
- 1
- 1
- 5
5
votes
2 answers
FileOptions.Asynchronous causes FileStream.BeginRead to block
Why does creating a FileStream with FileOptions.Asynchronous cause FileStream.BeginRead to block the calling thread?
Here is the code snippet:
private static Task ReadFileAsync(string filePath)
{
var file = new FileStream(filePath,…

dmg
- 608
- 8
- 15
3
votes
1 answer
.NET cancel stream BeginRead
I have not been able to find a way to cancel/terminate asynchronous read operation after successful HttpWebRequest. There is no way to set timeout, ThreadPool.RegisterWaitForSingleObject is not working too. And closing the underlying socket is not…
Daniel Iankov
3
votes
2 answers
Getting IOException with NetworkStream.BeginRead()
When running this code:
private async void StartChat(Object obj)
{
TcpClient me = (TcpClient)obj;
UpdateChatBox("Attempting read from server.");
myBuffer = new byte[BUFFER_SIZE];
while (true)
{
var myStream =…

TGreg
- 65
- 1
- 7
2
votes
1 answer
Asynchronous TcpClient not reading all the data in time
The code below works if there's not a lot of data from the server, or if there's a lot data and I uncomment the Thread.Sleep(500) line. I however don't want to use the Thread.Sleep line, but if I remove it, the program will finish before it read all…

user2238950
- 21
- 1
- 3
1
vote
1 answer
C# Winforms and NetworkStream.BeginRead(), how to open new form based on network event?
I'm having some serious troubles getting communication from one thread to another working between NetworkStream.BeginRead() and a WinForms class (I'm a real newbie when it comes to topics such as threading and Asynchronous calls).
In particular, I'm…

TC Fox
- 980
- 4
- 13
- 25
1
vote
0 answers
Is it possible to abort/cancel a FileStream.Beginread asynchronous read operation
I want to control a STM32 microcontroller using the USB interface. Jan Axelson (http://www.lvr.com/hidpage.htm#MyExampleCode) has created some applications to show the usage of the USB HID class which is now my base source.
To check if my device has…
user1085814
1
vote
0 answers
SerialPort BaseStream BeginRead never invokes callback
I have a SerialPort object I know is configured correctly because I can send data to the port and the DataReceived event is properly raised. However, when I try the solution presented in How to use SerialPort class more reliably which suggests…

Dan
- 1,215
- 1
- 10
- 22
1
vote
0 answers
C# TcpClient: Sending stops unexpectedly
In C# (a Unity script), I have a client that uses either an TcpClient to send and receive data. The client will send a fixed data string every "frame" to the server. The server just echoes back that same string. This is testing and simulation…

Jan Discart
- 167
- 1
- 1
- 13
1
vote
0 answers
Async Callback on custom queue
I am writing a class which uses the TCP-socket with "BeginRead"
As i see it, whenever data is read, a delegate to the callback function is placed in the threadpool queue whenever data is read (Is this correct?).
Now i was wondering if it was…

jrnv
- 63
- 1
- 6
1
vote
1 answer
How to read all requested data using NetworkStream.BeginRead?
There is a code of async server. Client sends Header - size of Data Block + Data Block.
Server reads asynchronously first Header and then Data Block.
I need, after I read Data Block run the BeginRead for Header reading part, to make threads…

user2377299
- 93
- 2
- 8