2
votes

When I call Thread.Abort I receive the following exception:

Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

Why is this happening?

1
give more details, what is your application doing? when do you call the Abort? running as admin user or normal user on which operating system etc etc...Davide Piras
@Davide: The thread retrieves data from a server. I am running as a normal user on Windows 7.Casebash

1 Answers

2
votes

Calling Thread.Abort requires the CAS (Code Access Security) permission SecurityPermission\ControlThread. This has nothing to do with the user's permissions, but rather with permissions granted to your code by the .NET CLR.

The ControlThread permission is considered a "dangerous" permission. By default in .NET 2.0, it is only granted to assemblies that are running locally on the machine. I'm guessing that your assembly is either being loaded from outside the local machine or is being run in a hosted CLR instance (such as ASP.NET). Either way, there are mechanisms in place for increasing your assembly's CAS permissions. If you need help with this, you will need to be more specific about how your assembly is being loaded.

That said, aborting threads using Thread.Abort is generally not recommended. You might want to consider investing in an alternate approach for stopping thread execution instead of spending time trying to avoid the SecurityException.