| |

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]

0

Threads

26

Posts

21

Credits

Newbie

Rank: 1

Credits
21

 China

Post time: 2020-4-6 00:30:02
| Show all posts
Return is the natural end, the key is to release unmanaged objects before return. Abort is the abnormal end in the main thread.
Reply

Use magic Report

2

Threads

13

Posts

12

Credits

Newbie

Rank: 1

Credits
12

 China

 Author| Post time: 2020-4-7 14:30:01
| Show all posts
I tested and found that the oService.SocketRun () function does not release the handle even if it returns immediately without writing any code.
Reply

Use magic Report

2

Threads

13

Posts

12

Credits

Newbie

Rank: 1

Credits
12

 China

 Author| Post time: 2020-4-7 18:30:02
| Show all posts
I haven't tried the "call GC.Collect ()" method, but it is strange if you call GC.Collect continuously in the main thread.
Reply

Use magic Report

0

Threads

4

Posts

5

Credits

Newbie

Rank: 1

Credits
5

 China

Post time: 2020-4-10 21:00:01
| Show all posts
The handle will be reclaimed after the instance osThread is confirmed to be invalid. You can throw events to the main thread before the end of the oService.SocketRun method, end the thread on the main thread (note the synchronization Invoke), and only forcefully recycle osThread. ).
Reply

Use magic Report

2

Threads

13

Posts

12

Credits

Newbie

Rank: 1

Credits
12

 China

 Author| Post time: 2020-4-12 15:30:01
| Show all posts
TO:btx221C # Thread object has no dispose method.
Reply

Use magic Report

0

Threads

8

Posts

5

Credits

Newbie

Rank: 1

Credits
5

 China

Post time: 2020-4-13 13:45:01
| Show all posts
Don't worry about this, the system will automatically recycle,
Microsoft's automatic recycling is used for this purpose
Reply

Use magic Report

0

Threads

89

Posts

51

Credits

Newbie

Rank: 1

Credits
51

 China

Post time: 2020-5-19 18:45:02
| Show all posts
After the thread runs, it will be automatically recovered. Originally, these tasks are not yours to manage.
osThread = null;
GC.Collect ();
Reply

Use magic Report

0

Threads

89

Posts

51

Credits

Newbie

Rank: 1

Credits
51

 China

Post time: 2020-5-19 21:00:01
| Show all posts
Originally, the system will manage things by itself, but it has to be done by myself. I don't think it makes much sense ..

personal opinion for reference only..
Reply

Use magic Report

2

Threads

27

Posts

14

Credits

Newbie

Rank: 1

Credits
14

 China

Post time: 2020-5-23 14:45:01
| Show all posts
In fact, I think this is normal.It is not the end of the thread, the handle will disappear immediately.
Here is my opinion:
The thread has its own counter and its own context. When the technical device = 0, the system will release resources. Note that it is system management, so there is also some time. We can often see the 3 states of the thread when we read the os book. There is a state called the zombie state, which is the zombie process under Linux. It means that it is over, but the system has not released resources, and its lifetime is this period of time. Windows is a multi-threaded model, its threads and unix The following processes are basically the same.
Reply

Use magic Report

2

Threads

27

Posts

14

Credits

Newbie

Rank: 1

Credits
14

 China

Post time: 2020-5-23 16:45:01
| Show all posts
Your return just means that you gave up the right to act on the thread, the effect at this time is that the counter will be -1. Nothing else
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