| |

VerySource

 Forgot password?
 Register
Search
Author: hitone

C # Create a thread After the thread is processed, use return to return, but the system handle is not released at all. O

[Copy link]

2

Threads

13

Posts

12

Credits

Newbie

Rank: 1

Credits
12

 China

 Author| Post time: 2020-6-2 10:15:02
| Show all posts
Because my program is a server, I need to constantly create new threads to handle client requests. If the waiting pressure is high, the handle will not be released and it will occupy system resources. Currently, thread pools have been used to solve this problem.
Reply

Use magic Report

0

Threads

6

Posts

6

Credits

Newbie

Rank: 1

Credits
6

 China

Post time: 2020-6-6 01:15:01
| Show all posts
Remember to release resources after the thread is used:
osThread.Close(); //or osThread.Kill();
Reply

Use magic Report

0

Threads

6

Posts

6

Credits

Newbie

Rank: 1

Credits
6

 Great Britain

Post time: 2020-6-6 20:30:01
| Show all posts
Hey, sorry, I see threads as processes.
The thread interruption method is this:
osThread.Join();
osThread.Abort();

It is better to add this sentence before the thread starts:
osThread.IsBackground=true;
osThread.Start();
Reply

Use magic Report

2

Threads

13

Posts

12

Credits

Newbie

Rank: 1

Credits
12

 China

 Author| Post time: 2020-6-7 06:45:02
| Show all posts
ok I will test it and see
Reply

Use magic Report

0

Threads

1

Posts

2

Credits

Newbie

Rank: 1

Credits
2

 China

Post time: 2020-6-11 08:30:01
| Show all posts
I don’t need to recycle when using threads, it seems that it will be automatically released after the method is finished.
Reply

Use magic Report

0

Threads

6

Posts

6

Credits

Newbie

Rank: 1

Credits
6

 Japan

Post time: 2020-6-11 14:15:01
| Show all posts
Remind:
Thread variables are best defined to run in another form or module, so in the event of closing that form:
osThread.Join();
osThread.Abort();
And release the resource form resource after the form is closed: frm.Dispose();
Normal threads will release resources accordingly.
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2020|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list