views:

64

answers:

2

Hi,

I've a strance behaviour with C#2, an exception is thrown will calling a lock(...). I have the following exception : System.Threading.ThreadAbortException: Thread was being aborted. at System.Threading.Monitor.Enter(Object obj)...

Have you seen that kind of exception ? TIA

A: 

My thoughts on this

a c# lock is implemented with Moniter object i.e. when you use Lock actually runtime create internally a Moniter object. try {

if(Moniter.TryEnetr(object obj))

{

} } finally

{ Moniter.Exit(); }

so it dependes upon the synchorization object , you are using i.e. lock(obj)

what object , you are using to lock the piece of code.

saurabh
A: 

This exception is being thrown because your thread is being aborted.

Threads can be aborted in one of several situations: another thread calls Thread.Abort, an AppDomain is being unloaded, or an ASP.NET application is being recycled.

Stephen Cleary