473,770 Members | 1,973 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

FileStream Beginread

Lou
I can't get it to work. Please help...
-louie

hPipe = CreateFile(conn ectionString,

GENERIC_WRITE | GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRIT E, 0,

OPEN_EXISTING, FILE_ATTRIBUTE_ NORMAL,HANDLE.Z ero);

if ((hPipe.ToInt32 ()) == INVALID_HANDLE_ VALUE)

{

blnConnected=fa lse;

return false;

}

//start an asyncronys read

IAsyncResult iAR;

byte[] byRequest=new byte[4095];

iAR=myStream.Be ginRead(byReque st,0,4096,ASync FileCallBackRea d(iAR),myStream )
;

public void ASyncFileCallBa ckRead(IAsyncRe sult iAR)

{

System.Text.ASC IIEncoding EnAscii;

System.Text.ASC IIEncoding EnUNI;

int byteCount;

string recData;

byte recReq[]=new byte[(Convert.ToByte (iAR.AsyncState )];

byteCount=myStr eam.EndRead(iAR );
recData = EnAscii.GetStri ng(recReq,0,byt eCount);
Nov 15 '05
15 10821
Lou <lo********@com cast.net> wrote:
I still get errors??

C:\Documents and Settings\LGarvi n.PINNACLE\My Documents\Visua l Studio
Projects\Window sApplication13\ DekoAutomation. cs(154): The best overloaded
method match for 'System.IO.Stre am.BeginRead(by te[], int, int,
System.AsyncCal lback, object)' has some invalid arguments
C:\Documents and Settings\LGarvi n.PINNACLE\My Documents\Visua l Studio
Projects\Window sApplication13\ DekoAutomation. cs(155): Argument '4': cannot
convert from 'WindowsApplica tion13.AsyncCal lback' to 'System.AsyncCa llback'


Have you declared your own delegate called AsyncCallback? You shouldn't
have done.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #11
Lou
John I'm making progress. I can now get the call back from the pipe, but how
do I read the data from the pipe??
Thanks again for all your help/patience.
-Lou

public void ASyncFileCallBa ckRead(IAsyncRe sult iAR)

{

//byte[] recResponse=iAR .AsyncState;

int byteCount;

int[] recData;

byteCount=myStr eam.EndRead(iAR );

recData=iAR.Asy ncState;

}

"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
Lou <lo********@com cast.net> wrote:
I still get errors??

C:\Documents and Settings\LGarvi n.PINNACLE\My Documents\Visua l Studio
Projects\Window sApplication13\ DekoAutomation. cs(154): The best overloaded method match for 'System.IO.Stre am.BeginRead(by te[], int, int,
System.AsyncCal lback, object)' has some invalid arguments
C:\Documents and Settings\LGarvi n.PINNACLE\My Documents\Visua l Studio
Projects\Window sApplication13\ DekoAutomation. cs(155): Argument '4': cannot convert from 'WindowsApplica tion13.AsyncCal lback' to
'System.AsyncCa llback'
Have you declared your own delegate called AsyncCallback? You shouldn't
have done.

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

Nov 15 '05 #12
Lou <lo********@com cast.net> wrote:
John I'm making progress. I can now get the call back from the pipe, but how
do I read the data from the pipe??


Uncomment the line you commented out, but include a cast:

byte[] recResponse = iAR.AsyncState;

then use

int byteCount = myStream.EndRea d(iAR);

and then bytes 0 to byteCount-1 are the data that's been read.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #13
Lou
the compiler doesn't like'

int byteCount = myStream.EndRea d(iAR);

C:\Documents and Settings\LGarvi n.PINNACLE\My Documents\Visua l Studio
Projects\Window sApplication13\ DekoAutomation. cs(229): Cannot implicitly
convert type 'object' to 'byte[]'

"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
Lou <lo********@com cast.net> wrote:
John I'm making progress. I can now get the call back from the pipe, but how do I read the data from the pipe??


Uncomment the line you commented out, but include a cast:

byte[] recResponse = iAR.AsyncState;

then use

int byteCount = myStream.EndRea d(iAR);

and then bytes 0 to byteCount-1 are the data that's been read.

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

Nov 15 '05 #14
Lou
I DID IT!!

byte[] recResponse=(by te[])iAR.AsyncState ;

int byteCount = myStream.EndRea d(iAR);

thanks for your support, your a patient person and its appreciated.


"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
Lou <lo********@com cast.net> wrote:
John I'm making progress. I can now get the call back from the pipe, but how do I read the data from the pipe??


Uncomment the line you commented out, but include a cast:

byte[] recResponse = iAR.AsyncState;

then use

int byteCount = myStream.EndRea d(iAR);

and then bytes 0 to byteCount-1 are the data that's been read.

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

Nov 15 '05 #15
Lou <lo********@com cast.net> wrote:
the compiler doesn't like'

int byteCount = myStream.EndRea d(iAR);

C:\Documents and Settings\LGarvi n.PINNACLE\My Documents\Visua l Studio
Projects\Window sApplication13\ DekoAutomation. cs(229): Cannot implicitly
convert type 'object' to 'byte[]'


I don't think that's the line it's complaining about. I think it's
complaining because you've done:

byte[] byRequest = iAR.AsyncState;

where you should have

byte[] byRequest = (byte[]) iAR.AsyncState;

(My fault for not putting it before.)

I think you could do with learning a bit more about the basics of C#
before going too much further with asynchronous stuff though - it would
help you solve a lot of your problems yourself.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #16

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

Similar topics

0
1830
by: Martyn Wynne | last post by:
Hi, Can anyone please tell me if there is any reason why when i am streaming from a webrequest (decompressing on route) to a file on the hard drive, i would be getting an exception of Filestream error System.StackOverflowException every time the file gets to 8580Kbs. Code is basically a modified Microsoft example, it errors on the line Dim ar As IAsyncResult = _
0
1271
by: Shane | last post by:
I want to use BeginRead on a socket stream. I want to abort the read if no data arrives within a certain time interval. I know i can't cancell the BeginRead directly but closing the socket seems to work. Does this cause any problems (Resource leaks etc) ? Should I also call EndRead after closing the socket even though it will it throw ? Has anyone done anything similar ? Shane
4
7208
by: 0to60 | last post by:
I have a class that wraps a TcpClient object and manages all the async reading of the socket. It works really nice, and I use it all over the place. But there's this ONE INSTANCE where I create one of these things and it WON'T read data. If I set a breakpoint in my EndRead callback, it never goes off. NOTHING is different from anywhere else I use this class, its just this one place. Now, if I create a second constructor for my class...
5
6421
by: Mike Robinson | last post by:
The Win32 SDK had a great function called "ReadFile" that was a model of simplicity. Now I'm starting to use the new .NET Framework, which is supposed to be an improvement but the file reading is (as far as I can tell) nowhere near as good. FileStream fs=new FileStream(FName); fs.BeginRead (Buffer,0,thisFile.Length,0,0); The last two arguments (the two closing zeroes) are for "AsyncCallback" and "stateObject." Microsoft's...
9
5855
by: Tom | last post by:
I am working with the this object as oppose to the StreamReader object becuase I need to access a file (to find the contents) while an external application is updating the file. When I was working with the StreamReader object I got a deadlock when I tried reading the file while my external application was writing to it. So far I am able to create a FileStream object and open the file in question (CrawlerBackup.txt). But I am unable to...
1
2952
by: Manuel Costa | last post by:
Hi, i was testing a network application that i've been working on which use .net socket components. To read from a socket i use the networkstream beginread. If the other side dies, beginread calls the callback delegate. Today i was testing this in my old laptop (celeron 553MHz) and verify an interesting thing. Callback is not called and this exception is captured by visual studio. An unhandled exception of type...
5
3691
by: Nadav | last post by:
Hi, I am using FileStream's Async API: BeginRead/EndRead, upon completion callback execution I use the read data and call EndRead, Taking that in mind, I Wonder... does calling EndRead will cause a context switch? What is the kernel object used for blocking EndRead calls? Event and mutex cause a context switch even when the object is signaled and no wait is needed, usage of critical section prevent this switch from happening... what is the...
6
5764
by: Stephen Brooker | last post by:
Hi all, I've got a basic TCP app that is giving me trouble. I have a separate class that takes care of the TCP connection, and uses the NetworkStreams BeginRead and EndRead with a callback function to deal with the server response. All works well and the data is received OK. Once all the data is received, the connection is closed and I fire an event indicating all is finished. The event is handled in the main form of the application and...
1
5333
by: ohmmega | last post by:
hello, i've a method in the form_load event witch calls 2 beginread statements (one after the other :) ) problem: during the second call it seem's that the callback won't be triggered. i've tried to wait for several seconds before calling the second call - no effect.
0
9618
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10259
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10101
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8933
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7456
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6710
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2849
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.