Click here to Skip to main content
15,891,473 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to plug usb into the pc will automatically copy the selected folder to usb, but have trouble:
Plug in usb 1 to pc then ok.
plug usb 2 into pc then usb 1 stop copy, when usb 2 copy finished, usb 1 continues.
Now I want to plug in multiple usb at the same time all are copy.


What I have tried:

private void OnDriveArrived(object sender, DriveDetectorEventArgs e)
       {

               string s = "Phát hiện ổ " + e.Drive + " Đã cắm vào";
               listBox1.Items.Add(s);

               string copy1 = textBox1.Text;
           try
           {

                   FileSystem.CopyDirectory(copy1, e.Drive, UIOption.AllDialogs, UICancelOption.DoNothing);


           }
           catch (Exception ex)
           {
               MessageBox.Show("Error : Kiểm tra đường dẩn mục copy",
                               "Error",
                               MessageBoxButtons.OK,
                               MessageBoxIcon.Error);
           }
           return;

       }
Posted
Updated 29-Mar-18 18:53pm
Comments
Member 13555640 30-Mar-18 0:09am    
Now I want to add a MessageBox to the message when the copy completed. Please just add more. Thank you very much

Quote:
Now I want to plug in multiple usb at the same time all are copy.

The answer is multithreading.
The main thread contain the usb listener and you launch a copy thread for each usb key as they are plugged.
 
Share this answer
 
Comments
Member 13555640 28-Mar-18 23:59pm    
Can you edit my code?
Member 13555640 30-Mar-18 0:07am    
Thanks you .
I have done it
Patrice T 30-Mar-18 1:58am    
Nice.
Member 13555640 30-Mar-18 0:09am    
Now I want to add a MessageBox to the message when the copy completed and
Automatically eject usb when finished. Please just add more. Thank you very much
Patrice T 30-Mar-18 1:59am    
Use Improve question to update your question.
So that everyone can pay attention to this information.
Or open a new question.
private void OnDriveArrived(object sender, DriveDetectorEventArgs e)
        {
           
               
                string s = "Phát hiện ổ " + e.Drive + " Đã cắm vào";
          
                listBox1.Items.Add(s);
           Thread thread = new Thread(() =>
            {
                try
                {
                    string copy1 = textBox1.Text;
                    FileSystem.CopyDirectory(
                            copy1,
                            e.Drive,
                            UIOption.AllDialogs,
                            UICancelOption.DoNothing);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error : " + ex.Message,
                                    "Error",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                }
            });
            thread.Start();
            
           
        }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900