472,784 Members | 877 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,784 software developers and data experts.

Shouldn't 'ReadFile' block when timeouts are specified ???

ORC
Shouldn't 'ReadFile' block when timeouts are specified even when running in
overlapped mode or am I wrong ???

Thanks
Ole
Nov 16 '05 #1
12 6794
ORC <or*@sol.dk> wrote:
Shouldn't 'ReadFile' block when timeouts are specified even when running in
overlapped mode or am I wrong ???


ReadFile being what, exactly? It's not coming up in the MSDN index...

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2
ORC
Sorry - the readfile is an API call but I write my application in C# and
don't know where else to place my question. The readfile is implemented
through P/Invoke. I have set the COMMTIMEOUTS (also part of the API) to
wait 2 seconds before timeing out during a call to readfile.

Thanks
Ole
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
ORC <or*@sol.dk> wrote:
Shouldn't 'ReadFile' block when timeouts are specified even when running in overlapped mode or am I wrong ???


ReadFile being what, exactly? It's not coming up in the MSDN index...

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #3
ORC <or*@sol.dk> wrote:
Sorry - the readfile is an API call but I write my application in C# and
don't know where else to place my question. The readfile is implemented
through P/Invoke. I have set the COMMTIMEOUTS (also part of the API) to
wait 2 seconds before timeing out during a call to readfile.


Ah, right. This is under the Compact Framework, correct? If so, I'd ask
in either one of the PocketPC groups, or the Compact Framework group.
There are likely to be more people with experience of the function
there.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #4
ORC
no it's not part of compact framework or a pocket pc - it's part of .NET and
C#. I've looking for a windows API group but such one doesn't seems to exist
any suggestion?

Thanks
Ole
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
ORC <or*@sol.dk> wrote:
Sorry - the readfile is an API call but I write my application in C# and
don't know where else to place my question. The readfile is implemented
through P/Invoke. I have set the COMMTIMEOUTS (also part of the API) to
wait 2 seconds before timeing out during a call to readfile.


Ah, right. This is under the Compact Framework, correct? If so, I'd ask
in either one of the PocketPC groups, or the Compact Framework group.
There are likely to be more people with experience of the function
there.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #5
ORC <or*@sol.dk> wrote:
no it's not part of compact framework or a pocket pc - it's part of .NET and
C#.
ReadFile itself isn't part of either C# or the .NET framework. When I
found ReadFile in the MSDN after removing the filter, it only came up
with WinCE references. Are you saying it's part of the "normal" Win32
as well? Maybe there are bits of MSDN I haven't installed...
I've looking for a windows API group but such one doesn't seems to exist
any suggestion?


The .interop group, perhaps?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #6
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote:

[about the ReadFile routine]
Are you saying it's part of the "normal" Win32
as well? Maybe there are bits of MSDN I haven't installed...


It's a Win32 API routine:
http://msdn.microsoft.com/library/de...e/readfile.asp
I've looking for a windows API group but such one doesn't seems to exist
any suggestion?


The .interop group, perhaps?


Or one of microsoft.public.win32.programmer.* if the question is more based
on that/those routine(s) itself/themselves.
Nov 16 '05 #7
AFAIK, the timeouts in the COMMTIMEOUTS structure set using SetCommTimeouts
apply only to serial ports. And even then, the overlapped operations will
never block, just return an ERROR_IO_PENDING. If you need a timeout, you
should wait on the overlapped event using the WaitOne() or similar function.

HTH,
Stefan

"ORC" <or*@sol.dk> wrote in message
news:ul***************@TK2MSFTNGP10.phx.gbl...
no it's not part of compact framework or a pocket pc - it's part of .NET
and
C#. I've looking for a windows API group but such one doesn't seems to
exist
any suggestion?

Thanks
Ole
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
ORC <or*@sol.dk> wrote:
> Sorry - the readfile is an API call but I write my application in C#
> and
> don't know where else to place my question. The readfile is implemented
> through P/Invoke. I have set the COMMTIMEOUTS (also part of the API)
> to
> wait 2 seconds before timeing out during a call to readfile.


Ah, right. This is under the Compact Framework, correct? If so, I'd ask
in either one of the PocketPC groups, or the Compact Framework group.
There are likely to be more people with experience of the function
there.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too


Nov 16 '05 #8
ORC
Thanks Stefan,

I'm using the readfile for the serial port in a very simple way: readfile
must block until all characters are read or until the timeout period is
reached but it must not block the writefile. Does any one have a very simple
code example on how to let the readfile block in overlapped mode like with
the suggested WaitOne function ??+

Thanks,
Ole

"Stefan Simek" <si********@kascomp.blah.sk> wrote in message
news:ee**************@TK2MSFTNGP11.phx.gbl...
AFAIK, the timeouts in the COMMTIMEOUTS structure set using SetCommTimeouts apply only to serial ports. And even then, the overlapped operations will
never block, just return an ERROR_IO_PENDING. If you need a timeout, you
should wait on the overlapped event using the WaitOne() or similar function.
HTH,
Stefan

"ORC" <or*@sol.dk> wrote in message
news:ul***************@TK2MSFTNGP10.phx.gbl...
no it's not part of compact framework or a pocket pc - it's part of .NET
and
C#. I've looking for a windows API group but such one doesn't seems to
exist
any suggestion?

Thanks
Ole
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
ORC <or*@sol.dk> wrote:
> Sorry - the readfile is an API call but I write my application in C#
> and
> don't know where else to place my question. The readfile is implemented > through P/Invoke. I have set the COMMTIMEOUTS (also part of the API)
> to
> wait 2 seconds before timeing out during a call to readfile.

Ah, right. This is under the Compact Framework, correct? If so, I'd ask
in either one of the PocketPC groups, or the Compact Framework group.
There are likely to be more people with experience of the function
there.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too



Nov 16 '05 #9
I guess you should avoid using the overlapped functions from C# at all.
You'll become responsible for pinning buffers, etc... I guess you should use
the FileStream, which is more or less a wrapper of the ReadFile/WriteFile
functionality. However, it doesn't have a wrapper for the CancelIo method
(not one I'm aware of), so you could possibly run into problems with
stopping the long-running read operation after your timeout expires. As for
the timeout, just issue a BeginRead() and start some timer along with it. If
the timeout expires sooner than the read operation is complete, it's up to
you what to do next...

HTH,
Stefan

"ORC" <or*@sol.dk> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Thanks Stefan,

I'm using the readfile for the serial port in a very simple way: readfile
must block until all characters are read or until the timeout period is
reached but it must not block the writefile. Does any one have a very
simple
code example on how to let the readfile block in overlapped mode like with
the suggested WaitOne function ??+

Thanks,
Ole

"Stefan Simek" <si********@kascomp.blah.sk> wrote in message
news:ee**************@TK2MSFTNGP11.phx.gbl...
AFAIK, the timeouts in the COMMTIMEOUTS structure set using

SetCommTimeouts
apply only to serial ports. And even then, the overlapped operations will
never block, just return an ERROR_IO_PENDING. If you need a timeout, you
should wait on the overlapped event using the WaitOne() or similar

function.

HTH,
Stefan

"ORC" <or*@sol.dk> wrote in message
news:ul***************@TK2MSFTNGP10.phx.gbl...
> no it's not part of compact framework or a pocket pc - it's part of
> .NET
> and
> C#. I've looking for a windows API group but such one doesn't seems to
> exist
> any suggestion?
>
> Thanks
> Ole
>
>
> "Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
> news:MP************************@msnews.microsoft.c om...
>> ORC <or*@sol.dk> wrote:
>> > Sorry - the readfile is an API call but I write my application in C#
>> > and
>> > don't know where else to place my question. The readfile is implemented >> > through P/Invoke. I have set the COMMTIMEOUTS (also part of the API)
>> > to
>> > wait 2 seconds before timeing out during a call to readfile.
>>
>> Ah, right. This is under the Compact Framework, correct? If so, I'd
>> ask
>> in either one of the PocketPC groups, or the Compact Framework group.
>> There are likely to be more people with experience of the function
>> there.
>>
>> --
>> Jon Skeet - <sk***@pobox.com>
>> http://www.pobox.com/~skeet
>> If replying to the group, please do not mail me too
>
>



Nov 16 '05 #10
ORC
I don't thinks that FileStream supports the serial port but maybe I'm wrong
?!?

Thanks,
Ole
"Stefan Simek" <si********@kascomp.blah.sk> wrote in message
news:uO**************@TK2MSFTNGP10.phx.gbl...
I guess you should avoid using the overlapped functions from C# at all.
You'll become responsible for pinning buffers, etc... I guess you should use the FileStream, which is more or less a wrapper of the ReadFile/WriteFile
functionality. However, it doesn't have a wrapper for the CancelIo method
(not one I'm aware of), so you could possibly run into problems with
stopping the long-running read operation after your timeout expires. As for the timeout, just issue a BeginRead() and start some timer along with it. If the timeout expires sooner than the read operation is complete, it's up to
you what to do next...

HTH,
Stefan

"ORC" <or*@sol.dk> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Thanks Stefan,

I'm using the readfile for the serial port in a very simple way: readfile must block until all characters are read or until the timeout period is
reached but it must not block the writefile. Does any one have a very
simple
code example on how to let the readfile block in overlapped mode like with the suggested WaitOne function ??+

Thanks,
Ole

"Stefan Simek" <si********@kascomp.blah.sk> wrote in message
news:ee**************@TK2MSFTNGP11.phx.gbl...
AFAIK, the timeouts in the COMMTIMEOUTS structure set using

SetCommTimeouts
apply only to serial ports. And even then, the overlapped operations will never block, just return an ERROR_IO_PENDING. If you need a timeout, you should wait on the overlapped event using the WaitOne() or similar

function.

HTH,
Stefan

"ORC" <or*@sol.dk> wrote in message
news:ul***************@TK2MSFTNGP10.phx.gbl...
> no it's not part of compact framework or a pocket pc - it's part of
> .NET
> and
> C#. I've looking for a windows API group but such one doesn't seems to > exist
> any suggestion?
>
> Thanks
> Ole
>
>
> "Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
> news:MP************************@msnews.microsoft.c om...
>> ORC <or*@sol.dk> wrote:
>> > Sorry - the readfile is an API call but I write my application in C# >> > and
>> > don't know where else to place my question. The readfile is

implemented
>> > through P/Invoke. I have set the COMMTIMEOUTS (also part of the API) >> > to
>> > wait 2 seconds before timeing out during a call to readfile.
>>
>> Ah, right. This is under the Compact Framework, correct? If so, I'd
>> ask
>> in either one of the PocketPC groups, or the Compact Framework group. >> There are likely to be more people with experience of the function
>> there.
>>
>> --
>> Jon Skeet - <sk***@pobox.com>
>> http://www.pobox.com/~skeet
>> If replying to the group, please do not mail me too
>
>



Nov 16 '05 #11
Errr... sorry, I missed that you're using it for serial port access. One way
to do what you want could be creating a FileStream with a handle to the COM
port created by CreateFile. I've heard of this, but I don't know if it
works. For another way (and probably forward-compatible with .NET 2.0), see

http://tinyurl.com/2ce6a

This is a quite old serial port wrapper from MS. It's buggy, but you usually
can work around most of the issues. It worked fine for me. It should work
well in your case, because you can freely combine synchronous / asynchronous
calls with this one (synchronous calls are in fact implemented roughly as
Begin...()/End...()).

btw., be careful about the memory leak mentioned in the discussion on the
component. I haven't met with it, but it surely is there.

HTH,
Stefan

"ORC" <or*@sol.dk> wrote in message
news:uS**************@TK2MSFTNGP14.phx.gbl...
I don't thinks that FileStream supports the serial port but maybe I'm wrong
?!?

Thanks,
Ole
"Stefan Simek" <si********@kascomp.blah.sk> wrote in message
news:uO**************@TK2MSFTNGP10.phx.gbl...
I guess you should avoid using the overlapped functions from C# at all.
You'll become responsible for pinning buffers, etc... I guess you should

use
the FileStream, which is more or less a wrapper of the ReadFile/WriteFile
functionality. However, it doesn't have a wrapper for the CancelIo method
(not one I'm aware of), so you could possibly run into problems with
stopping the long-running read operation after your timeout expires. As

for
the timeout, just issue a BeginRead() and start some timer along with it.

If
the timeout expires sooner than the read operation is complete, it's up
to
you what to do next...

HTH,
Stefan

"ORC" <or*@sol.dk> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
> Thanks Stefan,
>
> I'm using the readfile for the serial port in a very simple way: readfile > must block until all characters are read or until the timeout period is
> reached but it must not block the writefile. Does any one have a very
> simple
> code example on how to let the readfile block in overlapped mode like with > the suggested WaitOne function ??+
>
> Thanks,
> Ole
>
> "Stefan Simek" <si********@kascomp.blah.sk> wrote in message
> news:ee**************@TK2MSFTNGP11.phx.gbl...
>> AFAIK, the timeouts in the COMMTIMEOUTS structure set using
> SetCommTimeouts
>> apply only to serial ports. And even then, the overlapped operations will >> never block, just return an ERROR_IO_PENDING. If you need a timeout, you >> should wait on the overlapped event using the WaitOne() or similar
> function.
>>
>> HTH,
>> Stefan
>>
>> "ORC" <or*@sol.dk> wrote in message
>> news:ul***************@TK2MSFTNGP10.phx.gbl...
>> > no it's not part of compact framework or a pocket pc - it's part of
>> > .NET
>> > and
>> > C#. I've looking for a windows API group but such one doesn't seems to >> > exist
>> > any suggestion?
>> >
>> > Thanks
>> > Ole
>> >
>> >
>> > "Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
>> > news:MP************************@msnews.microsoft.c om...
>> >> ORC <or*@sol.dk> wrote:
>> >> > Sorry - the readfile is an API call but I write my application in C# >> >> > and
>> >> > don't know where else to place my question. The readfile is
> implemented
>> >> > through P/Invoke. I have set the COMMTIMEOUTS (also part of the API) >> >> > to
>> >> > wait 2 seconds before timeing out during a call to readfile.
>> >>
>> >> Ah, right. This is under the Compact Framework, correct? If so, I'd
>> >> ask
>> >> in either one of the PocketPC groups, or the Compact Framework group. >> >> There are likely to be more people with experience of the function
>> >> there.
>> >>
>> >> --
>> >> Jon Skeet - <sk***@pobox.com>
>> >> http://www.pobox.com/~skeet
>> >> If replying to the group, please do not mail me too
>> >
>> >
>>
>>
>
>



Nov 16 '05 #12
ORC
Thanks Stefan,

Have now downloaded the wrapper and will have a closer look at it.

Best regards
Ole

"Stefan Simek" <si********@kascomp.blah.sk> wrote in message
news:uR**************@tk2msftngp13.phx.gbl...
Errr... sorry, I missed that you're using it for serial port access. One way to do what you want could be creating a FileStream with a handle to the COM port created by CreateFile. I've heard of this, but I don't know if it
works. For another way (and probably forward-compatible with .NET 2.0), see
http://tinyurl.com/2ce6a

This is a quite old serial port wrapper from MS. It's buggy, but you usually can work around most of the issues. It worked fine for me. It should work
well in your case, because you can freely combine synchronous / asynchronous calls with this one (synchronous calls are in fact implemented roughly as
Begin...()/End...()).

btw., be careful about the memory leak mentioned in the discussion on the
component. I haven't met with it, but it surely is there.

HTH,
Stefan

"ORC" <or*@sol.dk> wrote in message
news:uS**************@TK2MSFTNGP14.phx.gbl...
I don't thinks that FileStream supports the serial port but maybe I'm wrong ?!?

Thanks,
Ole
"Stefan Simek" <si********@kascomp.blah.sk> wrote in message
news:uO**************@TK2MSFTNGP10.phx.gbl...
I guess you should avoid using the overlapped functions from C# at all.
You'll become responsible for pinning buffers, etc... I guess you should
use
the FileStream, which is more or less a wrapper of the
ReadFile/WriteFile functionality. However, it doesn't have a wrapper for the CancelIo method (not one I'm aware of), so you could possibly run into problems with
stopping the long-running read operation after your timeout expires. As

for
the timeout, just issue a BeginRead() and start some timer along with it. If
the timeout expires sooner than the read operation is complete, it's up
to
you what to do next...

HTH,
Stefan

"ORC" <or*@sol.dk> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
> Thanks Stefan,
>
> I'm using the readfile for the serial port in a very simple way:

readfile
> must block until all characters are read or until the timeout period
is > reached but it must not block the writefile. Does any one have a very
> simple
> code example on how to let the readfile block in overlapped mode like

with
> the suggested WaitOne function ??+
>
> Thanks,
> Ole
>
> "Stefan Simek" <si********@kascomp.blah.sk> wrote in message
> news:ee**************@TK2MSFTNGP11.phx.gbl...
>> AFAIK, the timeouts in the COMMTIMEOUTS structure set using
> SetCommTimeouts
>> apply only to serial ports. And even then, the overlapped operations

will
>> never block, just return an ERROR_IO_PENDING. If you need a timeout,

you
>> should wait on the overlapped event using the WaitOne() or similar
> function.
>>
>> HTH,
>> Stefan
>>
>> "ORC" <or*@sol.dk> wrote in message
>> news:ul***************@TK2MSFTNGP10.phx.gbl...
>> > no it's not part of compact framework or a pocket pc - it's part of >> > .NET
>> > and
>> > C#. I've looking for a windows API group but such one doesn't seems to
>> > exist
>> > any suggestion?
>> >
>> > Thanks
>> > Ole
>> >
>> >
>> > "Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
>> > news:MP************************@msnews.microsoft.c om...
>> >> ORC <or*@sol.dk> wrote:
>> >> > Sorry - the readfile is an API call but I write my application
in C#
>> >> > and
>> >> > don't know where else to place my question. The readfile is
> implemented
>> >> > through P/Invoke. I have set the COMMTIMEOUTS (also part of the

API)
>> >> > to
>> >> > wait 2 seconds before timeing out during a call to readfile.
>> >>
>> >> Ah, right. This is under the Compact Framework, correct? If so,

I'd >> >> ask
>> >> in either one of the PocketPC groups, or the Compact Framework

group.
>> >> There are likely to be more people with experience of the function >> >> there.
>> >>
>> >> --
>> >> Jon Skeet - <sk***@pobox.com>
>> >> http://www.pobox.com/~skeet
>> >> If replying to the group, please do not mail me too
>> >
>> >
>>
>>
>
>



Nov 16 '05 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: laurence | last post by:
I am implementing a comprehensive image-map generator utility, so have been studying W3C HTML 4.01 Specification (http://www.w3.org/TR/html4/struct/objects.html#h-13.6) on image maps (among other...
0
by: Mustafa Ahmad Malik | last post by:
Hello, I have wrapped the Win32 pipes function in C#. I have created named pipe with PIPE_WAIT in pipemode parameter like this pipehandle = CreateNamedPipe(_pipeName, PIPE_ACCESS_DUPLEX,...
3
by: Shawn August | last post by:
Hello: I am converting a working VB6 program to C#. During testing of the C# version, I noticed the ReadFile API is crashing. The parameters going into the this function are identical to the...
2
by: Schorschi | last post by:
Can't seemd to get ReadFile API to work! Returns invalid handle error? =========================================================================== Ok, the visual basic gurus, help! The...
4
by: GS | last post by:
Hi, Is it possible to use try-catch block to return back to processing on the same line where last error occured? Say I'm trying to establish connection to database in try {} and catching...
4
by: Eric Renken | last post by:
I am trying to do an Overlapped ReadFile on a HID device and it just isn't working for me. The WaitForSingleObject keeps giving me an error "The system cannot find the file specified." This...
4
by: andre rodier | last post by:
Hello, I need to display or propose a jpeg image on a web page. When I need to display the image, I use this code : header("Content-Length: $fileSize") ; header("Content-Type: $type") ;...
10
by: Hendrik van Rooyen | last post by:
While doing a netstring implementation I noticed that if you build a record up using socket's recv(1), then when you close the remote end down, the recv(1) hangs, despite having a short time out...
15
by: Ketchup | last post by:
Hello everyone, I have been stuck with this problem for quite some time now. I am working in VB.NET, using framework 1.0. I have to keep the compatibility down to the original .NET framework...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.