(Just damaged samsung memory card data recovery , the code will not be standardized) When uploading various files, you will need to upload them 1 by 1 in a queue. When uploading a particular file, the process is locked, along with the lock is unlocked right after the upload is complete. The upload button occasion code inside the key class: C # code // Get the file name array selected by the openFileDialog control (openFileDialog can choose various files) privatevoidbutton1_Click (objectsender, EventArgse) label1.Text = ''; try this.openFileDialog1 .ShowDialog (); path = this.openFileDialog1.FileNames; // Get the array of file names selected by the openFileDialog control stringstrpath = ''; for (inty = 0; ypath.Length; y ++) strpath + = path [y]; textBox1 .Text = strpath; catch this.lbl_ftpStakt.Text = 'Please select a file!'; // Upload button occasion privatevoidbutton2_Click (objectsender, EventArgse) this.lbl_ftpStakt.Visible = true; // Set the upload information label to be visible this.lbl_ftpStakt.Text = 'Connect to the server ...'; try for (i = 0; ipath.Length; i ++) filename = path [i] .ToString (); // Instantiate the event class myTestfo = newmyTest ( filename); fo.startUpEvent + = newmyTest.myUpEventsHandler (this.RunsOnWorkerThread); // Register event fo.mythreadStart (); // Call the class method FileInfop = newFileInfo (path [i] .ToString ()); uploadSQL (p. Name); // Upload to library // label1.Text = 'Upload successful'; catch strings = ''; for (intx = i; xpath.Length; x ++) FileInfofile = newFileInfo (path [i] .ToString ()); s + = file.Name + ''; this.lbl_ftpStakt.Text = 'Upload failed'; MessageBox.Show (s. ToString () + 'Upload failed', 'Prompt'); // Connect ftp upload publicvoidRunsOnWorkerThread (string_filename) // Block thread mt.WaitOne (); Interlocked.Increment (refflag); // Status value + 1this. lbl_ftpStakt.Text = 'Connecting to the server ...'; FileInfofileInf = newFileInfo (_filename); FtpWebRequestreqFTP; // Create FtpWebRequest object according to uri reqFTP = (FtpWebRequest) FtpWebRequest.Create (newUri ('ftp: //210.82.*** . *** / '+ fileInf.Name)); // ftp username and password reqFTP.Credentials = newNetworkCredential (' record ',' files '); // default is true, the connection will not be closed // in one command After being executed reqFTP.KeepAlive = false; // Specify what command to execute reqFTP.Method = WebRequestMethods.Ftp.UploadFile; // Specify the data transfer type reqFTP.UseBinary = true; // Notify the server of the size of the file when uploading the file reqFTP.ContentLength = fileInf.Length; // long_length = fileInf.Length; /////////// The buffer size is set to 2kbintbuffLength = 2 048; //// byte [] buff = newbyte [buffLength]; intcontentLen; // Open a file stream (System.IO.FileStream) to read the uploaded file FileStreamfs = fileInf.OpenRead (); try // upload The file write stream Streamstrm = reqFTP.GetRequestStream (); // 2kbcontentLen = fs.Read (buff, 0, buffLength) of the file stream every time read; intallbye = (int) fileInf.Length; intstartbye = 0; this.myProgressControl .Maximum = allbye; this.myProgressControl.Minimum = 0; this.myProgressControl.Visible = true; this.lbl_ftpStakt.Visible = true; this.lbl_ftpStakt.Text = 'server connection ...'; // stream content does not end while (contentLen! = 0) // corrupted samsung memory card data recovery from filestream to uploadstreamstrm.Write (buff, 0, contentLen); contentLen = fs.Read (buff, 0, buffLength); startbye + = contentLen; this.lbl_ftpStakt.Text = 'Uploaded:' + (int) (startbye / 1024) + 'KB /' + 'Total length:' + (int) (allbye / 1024) + 'KB' + '' + 'File name:' + fileInf. Name; myProgressControl.Value = startbye; // Close two streams strm.Close (); fs.Close (); this.myProgressControl.Visible = false; this.lbl_ftpStakt.Text = 'Upload successful!' free download full version samsung memory card data recovery software ( Exceptionex) MessageBox. Show (ex.Message, 'UploadError'); Interlocked.Decrement (refflag); mt.ReleaseMutex (); // Release thread Delegated event class that handles the upload thread C # code /// summary /// Delegated event class //// summaryclassmyTest publicstringfilename; publicdelegatevoidmyUpEventsHandler (string_filename); publiceventmyUpEventsHandlerstartUpEvent; publicmyTest () /// summary /////// summary /// paramname = File name uploaded by '_filename' /parampublicmyTest(string_filename)this.filename=_filename;///summary///Start a thread, execute event /////summarypublicvoidmythreadStart()Threadthr=newThread(newThreadStart(this.mystart )); thr.Start (); /// summary /// Start event //// summarypublicvoidmystart () startUpEvent (this.filename); |