List Info

Thread: Re: mutual exclusive lock




Re: mutual exclusive lock
user name
2007-10-09 07:46:08
Usually you lock on some object that other processes cant
lock on.
This will prevent you waiting in a deadlock.

 class C1
    {
        private static object LockObject = new object();

        public void SomeFunction()
        {
            // Lock on class type
            lock (typeof(C1))
            {
                //Critical Region
            }
        }

        public void SomeFunction2()
        {
            // Lock on unique object
            lock (LockObject)
            {
                //Critical Region
            }

        }

    }
On 10/8/07, Nitu Gupta <nitugupta5gmail.com> wrote:
>
>
> Hello Everyone,
>
>    I need to run a peice of code without any
interruptionsby other thread.
> In other words I want to put a mutual exclusion lock.
>
> There is a method that I need to call within that lock.
This method resides
> in a class that in turn resides in a classLibrary. How
can I call a monitor
> or lock method on the class.
>
> So for example I have a class Library called
classLibrary1. I have class
> inside the callsLibrary1 called Class1. I need to call
a method called
> getBytes() from class1.
> This method getBytes() in turn calls other methods in
the same class and
> different classes.
>
> How can I put a mutual exclusive lock until I am done
calling this method
> and get the return value from the getBytes().
>
> I read a microsoft document where it mentions that I
can use Lock() method
> and Monitor() method to put locks,
> but I am not sure how to call a method inside lock
method in order to
> execute this getBytes() method that resides in a class
library.
>
>
>
> lock(not sure what to call)
>
> or Monitor(not sure what to call)
>
> Any help will be apprecaited.
>
> Thanks.
>
>
>
>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "DotNetDevelopment, VB.NET, C# .NET,
ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting"
group.
To post to this group, send email to DotNetDevelopmentgooglegroups.com
To unsubscribe from this group, send email to
DotNetDevelopment-unsubscribegooglegroups.com
For more options, visit this group at
http:
//cm.megasolutions.net/forums/default.aspx
-~----------~----~----~----~------~----~------~--~---


[1]

about | contact  Other archives ( Real Estate discussion Medical topics )