public void CloseWavFile(bool isfilldata) { if (file == null) { return; } if (isfilldata) { wavhead.riff.ChunkSize = maxwavdatalen + 36; wavhead.data.ChunkSize = maxwavdatalen; } else { wavhead.riff.ChunkSize = wavdatalen + 36; wavhead.data.ChunkSize = wavdatalen; } //byte[] b = StructToBytes(wavhead, 44); //bin.Write(b, 0, 44); bin.Write(wavdata, 0, (int)wavdatalen); bin.Close(); file.Close(); Process.Start("speex_decoder.exe", filedir); UploadThread.EnqueuelTask(new UploadThread.UploadFiles { filename = System.IO.Path.GetFileName(filedir), filepath = System.AppDomain.CurrentDomain.BaseDirectory + System.IO.Path.GetDirectoryName(filedir) + "/" }); wavdata = null; Deformity_Data = null; bin = null; file = null; }
public string UploadFiles(CallType callType, string fileName = "file", int count = 1, int threads = 1) { InitConsole(); var consoleOut = new StringWriter(); var consoleOut1 = Console.Out; //Console.SetOut(consoleOut); string name; string ext; if (callType == CallType.Console) { name = ConfigurationManager.AppSettings["SourcePath"] + Path.GetFileNameWithoutExtension(fileName);; ext = !string.IsNullOrEmpty(Path.GetExtension(fileName)) ? Path.GetExtension(fileName) : "docx"; } else { name = fileName; ext = ""; } var total = count; var offset = total / threads; var parameters = new UploadParams { Offset = 0, Count = offset, Config = _config, FileName = name, FileType = ext }; for (int i = 0; i < threads; i++) { parameters.Offset = i * offset; var upload = new UploadThread("THREAD " + i + ", Upload of " + offset + name + ext, parameters); } //var parametersXlsx = new UploadParams //{ // Offset = 0, // Count = offset, // Config = _config, // FileName = name, // FileType = "xlsx" // //FileType = !string.IsNullOrEmpty(ext) ? ext : "xlsx" //}; //for (int i = 0; i < threads; i++) //{ // parametersXlsx.Offset = i * offset; // var uploadXlsx = new UploadThread("THREAD " + i + ", View PDF of " + offset + " XLSX", parametersXlsx); //} //var parametersPptx = new UploadParams //{ // Offset = 0, // Count = offset, // Config = _config, // FileName = name, // FileType = "pptx" // //FileType = !string.IsNullOrEmpty(ext) ? ext : "pptx" //}; //for (int i = 0; i < threads; i++) //{ // parametersPptx.Offset = i * offset; // var uploadPptx = new UploadThread("THREAD " + i + ", View PDF of " + offset + " PPTX", parametersPptx); //} return("Upload success!"); return(consoleOut1.ToString()); return(consoleOut.ToString()); }
private void btn_Upload_Click(object sender, EventArgs e) { try { int _hasCount = 0; _killThread = false; foreach (Control c in panel1.Controls) { if (c is PictureBox && ((PictureBox)c).ImageLocation != null) { _hasCount++; Label _lab = new Label(); LinkLabel _linkLab = new LinkLabel(); string _name = "lab_Progress" + c.Name.Substring(c.Name.Length - 1); string _linkName = "link_" + c.Name.Substring(c.Name.Length - 1); foreach (Control x in panel1.Controls) { if (x.Name.Equals(_name)) { _lab = (Label)x; } if (x.Name.Equals(_linkName)) { _linkLab = (LinkLabel)x; } } _lab.Text = "进度:0%"; _lab.Visible = true; _linkLab.Visible = false; //多线程 UploadThread utc = new UploadThread(); utc._blockSize = _blockSize; utc._shopCode = _shopCode; utc._carID = _carID; UploadThread._killThread = _killThread; //订阅事件 utc.successEvent += new EventHandler(utc_successEvent); utc.failEvent += new EventHandler(utc_failEvent); utc.hadExistEvent += new EventHandler(utc_hadExistEvent); utc.progressEvent += new EventHandler(utc_progressEvent); utc.stopEvent += new EventHandler(utc_stopEvent); ParameterizedThreadStart ts = new ParameterizedThreadStart(utc.StartUpload); Thread td = new Thread(ts); td.IsBackground = true; //td.SetApartmentState = ApartmentState.STA; td.Start(((PictureBox)c).ImageLocation); _threadList.Add(td); } } if (_hasCount > 0) { btn_Upload.Enabled = false; } else { MessageBox.Show("请选择需要上传的图片!"); btn_Sel1.PerformClick(); } } catch (Exception ex) { MessageBox.Show(ex.Message); //CarLog.WriteLog(ex.Message); } }