473,406 Members | 2,439 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

File size is larger after beginwrite

Chi
I am a newibe of C# and async programming
thx for your help. I think most likely is my logical problem but i cant
figure it out

using System.IO;
using System.Text;
using System;
class Class1
{
static void Main()
{
Class1 a = new Class1();
a.Run();
Console.ReadLine();

}

void cB(IAsyncResult ar)
{

fsOut.EndWrite(ar);
fsIn.BeginRead(buffer,0,buffer.Length,new AsyncCallback(write),null);
}
void write(IAsyncResult ar)
{
int byteRead=fsIn.EndRead(ar);
if(byteRead==0)
{
fsOut.Write(buffer,0,buffer.Length);
fsOut.Close();
fsIn.Close();
}
else
{
fsOut.BeginWrite(buffer,0,buffer.Length,new AsyncCallback(cB),null);
}

}

public void Run()
{
fsOut = new
FileStream("Result.jpg",FileMode.Create,FileAccess .Write,FileShare.ReadWrite,2048,true);
fsIn= new
FileStream("test.jpg",FileMode.Open,FileAccess.Rea d,FileShare.ReadWrite,2048,true);
fsIn.BeginRead(buffer,0,buffer.Length,new AsyncCallback(write),null);
}
Class1()
{

buffer=new byte[2048];
}
//int LastResult;
private FileStream fsIn;
private FileStream fsOut;
byte [] buffer;


}
Jan 30 '06 #1
1 1802
Chi wrote:
I am a newibe of C# and async programming
thx for your help. I think most likely is my logical problem but i cant
figure it out


Well, it always helps if you describe what the problem is as well as
providing code. However, you certainly *do* have a problem, in that
your call to BeginWrite is assuming that it's managed to read a whole
buffer, instead of writing out bytesRead amount of data.

You're also writing out a full buffer's worth of data even if you
haven't read anything (where you shouldn't be writing anything).

Jon

Jan 30 '06 #2

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

Similar topics

0
by: PeterB | last post by:
Hi! I am using the script below to download files, that are in a non-public directory, from my site. The "smaller files" section works for smaller files. However when the files are getting...
6
by: Andrew Clark | last post by:
*** post for FREE via your newsreader at post.newsfeed.com *** Hello all, I recall several threads over the years about how reading file size cannot be done consistantly or portably, but I...
1
by: Jeff Weber | last post by:
First, my question: Should I use Write or BeginWrite (sync or async) to stream data to my clients. Details: On the server I have a custom circular data buffer that receives byte array data...
8
by: luis molina Micasoft | last post by:
it seems that when i do file.copy the svchost.exe is hanged, i mean if i make 40 threads of file.copy , 40 copys of files at same time the system is going down and stop responding, this is when i'm...
5
by: Claudio Grondi | last post by:
I have just started to play around with the bsddb3 module interfacing the Berkeley Database. Beside the intended database file databaseFile.bdb I see in same directory also the __db.001...
1
by: MSDN | last post by:
Does anyone know how to do this with a readline statement or equivalent method? Thanks in advance. Chris
5
by: Jefferis NoSpamme | last post by:
Hi all, I'm trying to limit the file size of an image submission and I keep running into various problems. I've got most of it working, but I'm stumped and I have a basic question as to WHY this...
6
by: bobby | last post by:
hi group, Does the header file size or number in include(s) effect the size of executable file? In other world if i chose a large header file and include it with my source file does it increase...
4
by: rsaharia | last post by:
Hello All, I need help with this particular .pl file I picked up from http://www.veritools-usa.com/xnf2vhdl.htm What it's supposed to do is really convert an xnf file to a vhdl file. I need it for...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...
0
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...

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.