C # resolves files that are resource-consuming, methods that cannot be deleted or modified _c# tutorial

Source: Internet
Author: User

Copy Code code as follows:
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>
The method that the thread executes, Telnet gets the data
</summary>
private void Openthread_telnet (Object obj)
{
Telnet_manage Manage = new Telnet_manage ();
Try
{
Manage. Printbysockets (NULL, wy_name, table, PROGRESSBAR1, Label2);
String LocalPath = environment.currentdirectory + @ "\ne_data\wy\" + wy_name;
If MessageBox.Show (this, "Data printing is done!") \ n File Location: "+ LocalPath +" \ n Enter the directory? "," hint ", messageboxbuttons.yesno) = = Dialogresult.yes)
{
System.Diagnostics.Process.Start (LocalPath);
}
This. Close ();
System.Threading.Thread.CurrentThread.Abort ();//Terminate current thread
}
catch (Exception e)
{
MessageBox.Show (This, "Print data failed!") "," hint ");
System.Threading.Thread.CurrentThread.Abort ();//Terminate current thread
This. Close ();
}
System.Threading.Thread.CurrentThread.Abort ();//Terminate current thread
}

private void Button1_Click (object sender, EventArgs e)
{
System.Threading.Thread.CurrentThread.Abort ();//Terminate current thread
if (parameterthread_t!= null)
{
Parameterthread_t.interrupt ();
Parameterthread_t.abort ();
Parameterthread_t.join ();

Gc. Collect ();
}
This. Close ();
}

Example: in the WinForm window, start a thread in the OnShow event to execute the Telnet program. When the Abort button (button1_click) is clicked, the thread is aborted and the file resource occupied by the current thread is freed.

Key: parameterthread_t.abort ();p arameterthread_t.join (); Gc. Collect (); This means that the thread is abort () to stop the thread from executing, Join (), the thread hangs until the thread aborts, and then the GC reclaims the resource.

The above is the C # solution files are occupied with all the content of resources, I hope to give you a reference, but also hope that we support the cloud habitat community.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.