468,532 Members | 1,653 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,532 developers. It's quick & easy.

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 6577
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Mustafa Ahmad Malik | last post: by
3 posts views Thread by Shawn August | last post: by
4 posts views Thread by GS | last post: by
4 posts views Thread by Eric Renken | last post: by
10 posts views Thread by Hendrik van Rooyen | last post: by
15 posts views Thread by Ketchup | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.