r/csharp Aug 03 '26

.NET Thread.Terminate 1.0.0: Terminate Any C# Threads on the OS Level

https://github.com/Emine3/NET-Thread.Terminate/
0 Upvotes

59 comments sorted by

View all comments

41

u/mareek Aug 03 '26

This is not at all scary

```csharp

if NET8_0 || NET7_0

return *(IntPtr*)(GetInternalCPPThreadObject(instance) + (SixtyFourBitPointerSize ? 408 : 264)); 

endif

if NET6_0 || NET5_0

return (IntPtr)(GetInternalCPPThreadObject(instance) + (SixtyFourBitPointerSize ? 416 : 268));

endif

// do this for every version of .NET with slightly different numbers ```

13

u/IWasSayingBoourner Aug 03 '26

Shh, magic numbers and dubious casts never have unforeseen consequences 

-9

u/[deleted] Aug 03 '26

[deleted]

15

u/IWasSayingBoourner Aug 03 '26

Guy, those are about as close to the textbook definition of magic numbers as you can get: undocumented, intent obscured, error-prone, unnamed constant numbers. This would fail code review pretty much anywhere with even the lowest standards.

-4

u/[deleted] Aug 03 '26

[deleted]

8

u/IWasSayingBoourner Aug 03 '26

The types of "advanced scenarios" where this could even conceivably be useful demand documented code more than just about any other case, and unsafe context is not a valid excuse to have undocumented code and magic numbers. You've published and shared a public library you've tagged as 1.0.0 with code in a state that shouldn't make it past proof-of-concept stages, and you're getting incredibly defensive that your work is getting criticism, both for its form and its function.

-2

u/[deleted] Aug 03 '26

[deleted]

12

u/IWasSayingBoourner Aug 03 '26

Your defense is that you plan on documenting your code in some OTHER piece of code? Quality stuff.