基本信息
源码名称:c#大文件分片上传demo
源码大小:0.06M
文件格式:.zip
开发语言:C#
更新时间:2019-06-15
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 6 元 
   源码介绍

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Runtime.InteropServices;
//using FileCut.NetTrans;
using System.Runtime.Serialization.Formatters.Binary;
using FileCut.FileHandle;

namespace FileCut
{
    public partial class Form1 : Form
    {
        IFileCut filecut;
        public Form1()
        {
            InitializeComponent();           
           
        }

        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                this.textBox1.Text = ofd.FileName;
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (filecut == null)
            {
                FactoryOfIFileCut factory = new FactoryOfIFileCut();
                filecut = factory.CreateFileCutObject("FileSplit", textBox1.Text);
            }
            if (filecut == null)
            {
                MessageBox.Show("文件不存在");
                return;
            }
           
            long ave= request(filecut,listView1);
            label4.Text=string.Format("平均耗时{0}毫秒",ave);
        }

        private long request(IFileCut fc,ListView lv)
        {
            Random rand = new Random();
            fc.PieceSize = int.Parse(tbPieceSize.Text) * 1024;
            lb_result.Text = string.Format("分片结果:共分为{0}片", fc.PieceCount);

            lv.Items.Clear();
            long totoatime = 0;
            int times = 50;
            for (int i = 0; i < times; i  )
            {
                int index = rand.Next(fc.PieceCount);
                DateTime old = DateTime.Now;
                fc.getPiece(index);
                TimeSpan ts = DateTime.Now - old;
                long t = ts.Ticks;
                totoatime  = t;
                //显示在列表中
                ListViewItem lvi = new ListViewItem(index.ToString());
                lvi.SubItems.Add(new ListViewItem.ListViewSubItem(lvi, t.ToString()));
                lv.Items.Add(lvi);
            }
            return totoatime / times;
        }

        private void button3_Click(object sender, EventArgs e)
        {
            FactoryOfIFileCut factory = new FactoryOfIFileCut();
            IFileCut fc = factory.CreateFileCutObject("BufferedFileSplit", textBox1.Text);
           
            long ave = request(fc, listView2);
            label6.Text = string.Format("平均耗时{0}毫秒", ave);

        }
    }
}