| |

VerySource

 Forgot password?
 Register
Search
View: 3543|Reply: 25

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

23

Posts

15.00

Credits

Newbie

Rank: 1

Credits
15.00

 China

Post time: 2020-2-9 00:00:01
| Show all posts |Read mode
Use the following code to create the thread
osThread = new Thread (new ThreadStart (oService.SocketRun));
osThread.Start ();
oService.SocketRun uses return to return after completing the task
I found that the handle added by the creating thread is not released. Is there any way for the prawns to release the handle, or what other methods are automatically terminated by the child thread without the need to terminate by the parent thread? Thanks a lot
Reply

Use magic Report

0

Threads

15

Posts

10.00

Credits

Newbie

Rank: 1

Credits
10.00

 China

Post time: 2020-4-1 21:45:01
| Show all posts
Can be placed in the thread pool
Reply

Use magic Report

2

Threads

23

Posts

15.00

Credits

Newbie

Rank: 1

Credits
15.00

 China

 Author| Post time: 2020-4-2 10:00:02
| Show all posts
Can't use the thread pool solve the problem of handle growth?
Reply

Use magic Report

0

Threads

9

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

Post time: 2020-4-2 15:15:01
| Show all posts
oService.SocketRun Of course the thread will end after the task is completed. It is normal that osThread is not empty. This needs to be collected by the GC.
Reply

Use magic Report

0

Threads

110

Posts

63.00

Credits

Newbie

Rank: 1

Credits
63.00

 China

Post time: 2020-4-2 17:45:01
| Show all posts
Don't worry about this, it will be automatically recycled ..
Reply

Use magic Report

2

Threads

23

Posts

15.00

Credits

Newbie

Rank: 1

Credits
15.00

 China

 Author| Post time: 2020-4-3 00:15:01
| Show all posts
I watched for a long time and for a few hours, I found that the number of handles increased due to the creation thread was not restored due to garbage collection at runtime
Reply

Use magic Report

0

Threads

9

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

Post time: 2020-4-4 19:15:01
| Show all posts
Call GC.Collect (); force collection
Reply

Use magic Report

0

Threads

27

Posts

21.00

Credits

Newbie

Rank: 1

Credits
21.00

 China

Post time: 2020-4-5 01:30:01
| Show all posts
It is better to let the thread end naturally, without returning
Reply

Use magic Report

0

Threads

8

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

Post time: 2020-4-5 17:30:02
| Show all posts
Is there any problem with return?
Reply

Use magic Report

0

Threads

9

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

Post time: 2020-4-5 19:15:01
| Show all posts
No
Reply

Use magic Report

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

Points Rules

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

Quick Reply To Top Return to the list