SoFunction
Updated on 2025-03-07

C# How to solve the problem that files are occupied and cannot be deleted or modified

Thread parameterThread_t = null; 
private void Print_DetailForm_Shown(object sender, EventArgs e) 

 
    parameterThread_t = new Thread(new ParameterizedThreadStart(this.openThread_telnet)); 
    //parameterThread_t.IsBackground = false; 
    parameterThread_t.Start(null); 

 
/// <summary> 
/// Method of thread execution, telnet obtains data
/// </summary> 
private void openThread_telnet(Object obj) 

    //TelNet_Manage manage = new TelNet_Manage(); 
    try 
    { 
        (null, wy_name, table, progressBar1, label2); 
        String localPath = + @"\Ne_data\wy\" + wy_name; 
if ((this,"Data printing is completed!\nFile location: " + localPath + "\nDo you enter this directory?", "Tip", ) == )
        { 
            (localPath); 
        } 
        (); 
();//Terminate the current thread
    } 
    catch(Exception e) 
    { 
(this,"Print data failed!","Tip");
();//Terminate the current thread
        (); 
    } 
();//Terminate the current thread

 
private void button1_Click(object sender, EventArgs e) 

//();//Terminate the current thread
    if (parameterThread_t != null) 
    { 
        parameterThread_t.Interrupt(); 
        parameterThread_t.Abort(); 
        parameterThread_t.Join(); 
         
        (); 
    } 
    (); 
}