【发布时间】:2015-09-08 07:43:58
【问题描述】:
我有一个类,它每次接收缓冲区时都应该附加到更大的字节数组,但它只在第一次进行块复制,然后它不会复制任何东西
缓冲区第一次进入类时,它会复制 allData 中的内容。但是第二次它全为零,尽管缓冲区包含数据。
这是我的代码:
public Boolean WriteBlobsToDB(byte[] buffer, int offset, int fileSize, string fileName, string fileType, string user, int count, int NChunks, string md5Src,int id)
{
bool ret = false;
int l = buffer.Length; // The buffer length is almost 2 MB
var allData = new byte[fileSize];
int offst = count * offset; // count is 0 the first timethen each time a new buffer comes, the value of count in count++
Buffer.BlockCopy(buffer, 0, allData, offst, fileSize);
if (count == NChunks-1 ) // NChunks is the number of how many time the buffer would be passed here
{ // the meaning of this if is that, when all the buffer of a file is passed then move to the database and upload the table
File_List fl = new File_List();
fl.FileName = fileName;
fl.Id = id;
fl.FileType = fileType;
fl.MD5 = md5Src;
fl.Data = new Binary(allData);
try
{
dc.SubmitChanges();
}
catch (Exception e)
{
Console.WriteLine(e);
}
}
return ret;
}
【问题讨论】:
-
我在这里看不到任何循环
-
没有循环,这是每次收到块时从处理程序调用的类
-
输入输出是什么?您正在将数据复制到名为“allData”的局部变量中。
-
变量“fl”未在任何地方定义。那个“wfl”是错字吗?
-
我向你保证:
Buffer.BlockCopy工作得很好。问题在于您如何使用它,但我们没有足够的上下文来正确评估它;一个简单的可重现示例会很棒,但是:不是这样。
标签: c# sql arrays buffer varbinary