我正在做一個ftp項目,它會做多次上傳,我正在做的過程是壓縮文件然後加密,然後切成幾塊併發送給服務器,我將所有這些東西分配給thread.likewise線程將在那裏爲我分配的每個文件。線程問題
這是新的代碼塊,它只有一個功能,在這裏出現了同樣的錯誤 也請幫我找出什麼是錯在這裏
public partial class Form1 : Form
{ ArrayList的AscendingList =新的ArrayList(); ListViewItem Litem = null; 線程MyThread = null; ThreadStart Starter = null;
public Form1()
{
InitializeComponent();
}
private void btn_split_Click(object sender, EventArgs e)
{
foreach (ListViewItem litem in listView1.Items)
{
Starter = delegate { SplitFile(litem.Text,litem.SubItems[1].Text,int.Parse(litem.SubItems[2].Text)); };
MyThread = new Thread(Starter);
MyThread.IsBackground = true;
MyThread.Start();
}
}
public void SplitFile(string inputFile, string outputPrefix, int chunkSize)
{
int pointr = 0;
byte[] buffer = new byte[chunkSize];
using (FileStream fs = new FileStream(inputFile, FileMode.Open, FileAccess.Read, FileShare.None))
{
int index = 0;
pointr = fs.Read(buffer, 0, buffer.Length);
while (pointr != 0)
{
using (FileStream fso = new FileStream(outputPrefix + "\\" + index + ".log", FileMode.Create))
{
AscendingList.Add(fso.Name);
fso.Write(buffer, 0, pointr);
pointr = fs.Read(buffer, 0, buffer.Length);
}
index++;
}
}
}
private void button1_Click(object sender, EventArgs e)
{
Litem = new ListViewItem();
Litem.Text = "E:\\butterfly.mpg";
Litem.SubItems.Add("H:\\karthik");
Litem.SubItems.Add("102400");
listView1.Items.Add(Litem);
}
private void button2_Click(object sender, EventArgs e)
{
Litem = new ListViewItem();
Litem.Text = "E:\\karthik.mpeg";
Litem.SubItems.Add("H:\\karthik\\karthik");
Litem.SubItems.Add("102400");
listView1.Items.Add(Litem);
}
}
請修復格式。 – Yogesh 2009-11-04 05:44:46
您能提供異常消息和堆棧跟蹤嗎? – Jehof 2009-11-11 09:14:24
請使用'Path.Combine()'! – knoopx 2009-11-15 22:32:43