¡@

Home 

c# Programming Glossary: lock

Why is lock(this) {…} bad?

http://stackoverflow.com/questions/251391/why-is-lockthis-bad

is lock this &hellip bad The MSDN documentation says that public class.. that public class SomeObject public void SomeOperation lock this Access instance variables is is a problem if the instance.. be accessed publicly . I'm wondering why Is it because the lock will be held longer than necessary Or is there some more insidious..

Dynamic LINQ OrderBy on IEnumerable<T>

http://stackoverflow.com/questions/41244/dynamic-linq-orderby-on-ienumerablet

Note that the choice of Hashtable is due to favorable locking semantics using Microsoft.CSharp.RuntimeBinder using System.. Func dynamic object accessors name if accessor null lock accessors accessor Func dynamic object accessors name if..

Creating a blocking Queue<T> in .NET?

http://stackoverflow.com/questions/530211/creating-a-blocking-queuet-in-net

a blocking Queue T in .NET I have a scenario where I have multiple.. size all threads that are filling the queue will be blocked on add until an item is removed from the queue. The solution.. behavior in the BCL that I should be using internal class BlockingCollection T CollectionBase IEnumerable todo might be worth..

Random number generator only generating one random number

http://stackoverflow.com/questions/767999/random-number-generator-only-generating-one-random-number

Every time you do new Random it is initialized using the clock. This means that in a tight loop you get the same value lots.. new object public static int RandomNumber int min int max lock syncLock synchronize return random.Next min max Edit see comments.. random.Next min max Edit see comments why do we need a lock here Basically Next is going to change the internal state of..

Lock Windows workstation programmatically in C#

http://stackoverflow.com/questions/1263047/lock-windows-workstation-programmatically-in-c-sharp

Windows workstation programmatically in C# I ran into this.. DllImport user32.dll SetLastError true static extern bool LockWorkStation ... if LockWorkStation throw new Win32Exception Marshal.GetLastWin32Error.. true static extern bool LockWorkStation ... if LockWorkStation throw new Win32Exception Marshal.GetLastWin32Error..

Throw a NullReferenceException while calling the set_item method of a Dictionary object in a multi-threding scenario

http://stackoverflow.com/questions/1320621/throw-a-nullreferenceexception-while-calling-the-set-item-method-of-a-dictionary

only one thread at a time accesses the Dictionary . Edit Lock around the accesses separately so that you aren't inside a lock..

Monitor vs WaitHandle based thread sync

http://stackoverflow.com/questions/1355398/monitor-vs-waithandle-based-thread-sync

reading this article that it is better to use Monitor Lock for thread synchronisation as it does not use native resources..

Volatile vs. Interlocked vs. lock

http://stackoverflow.com/questions/154551/volatile-vs-interlocked-vs-lock

What are the real-world pros and cons of each of the major mocking frameworks?

http://stackoverflow.com/questions/1718463/what-are-the-real-world-pros-and-cons-of-each-of-the-major-mocking-frameworks

Can mock anything Cons Very invasive Potential Vendor Lock In Does not encourage good design NMock Pros Encourages good..

Using lock statement within a loop in C#

http://stackoverflow.com/questions/2113261/using-lock-statement-within-a-loop-in-c-sharp

method. For the record I did considered the Double Lock Check patterned however it is does not seem to be recommend.. blog 2006 01 26 BrokenVariantsOnDoublecheckedLocking.aspx and http www.bluebytesoftware.com blog 2007 02 19 RevisitedBrokenVariantsOnDoubleCheckedLocking.aspx.. blog 2007 02 19 RevisitedBrokenVariantsOnDoubleCheckedLocking.aspx And this SO question has some good discussion http stackoverflow.com..

reference assignment is atomic so why is Interlocked.Exchange(ref Object, Object) needed?

http://stackoverflow.com/questions/2192124/reference-assignment-is-atomic-so-why-is-interlocked-exchangeref-object-object

volatile keyword and simple assigment I should use InterLocked.Exchange because he said that on some platforms it's not guaranteed.. reason why you ought to be using Interlocked.Exchange. Lock free programming is insanely difficult and the moment you depart.. understand how it works and should not be using volatile. Lock free programs are very difficult to get right make sure that..

Lock-free multi-threading is for real threading experts

http://stackoverflow.com/questions/2528969/lock-free-multi-threading-is-for-real-threading-experts

free multi threading is for real threading experts I was reading.. from the beginning was not so precise in the first place. Locks in .NET result in an implicit memory barrier so you are safe..

Lock statement vs Monitor.Enter method

http://stackoverflow.com/questions/2837070/lock-statement-vs-monitor-enter-method

statement vs Monitor.Enter method I suppose it is an interesting.. ConsoleApplication2.Test test2 2 bool lockTaken 3 bool s__LockTaken0 4 class ConsoleApplication2.Test CS 2 0000 5 bool CS 4.. L_001a dup L_001b stloc.s CS 2 0000 L_001d ldloca.s s__LockTaken0 L_001f call void mscorlib System.Threading.Monitor Enter..

Multithreading a large number of web requests in c#

http://stackoverflow.com/questions/4277844/multithreading-a-large-number-of-web-requests-in-c-sharp

is below is this the best way to go about this Semaphore Lock new Semaphore 10 10 List string folderPathList new List string.. populated foreach string folderPath in folderPathList Lock.WaitOne new Thread delegate WebRequest request WebRequest.Create.. WebResponse response request.GetResponse response.Close Lock.Release .Start for int i 1 i 10 i Lock.WaitOne The exception..

Lock (Monitor) internal implementation in .NET

http://stackoverflow.com/questions/5111779/lock-monitor-internal-implementation-in-net

Monitor internal implementation in .NET For mastering of some.. primitives. Here is the question how implemented Lock Monitor in .NET I'm intrested in such points does it utilize..

How do I detect a Lock This Computer command from a WPF application?

http://stackoverflow.com/questions/652550/how-do-i-detect-a-lock-this-computer-command-from-a-wpf-application

do I detect a Lock This Computer command from a WPF application Would prefer an.. life of me figure out how to detect or receive an event on Lock. Thanks for any assistance. c# wpf desktop locking share.. check to see if the Reason is SessionSwitchReason .SessionLock using Microsoft.Win32 ... Somewhere in your startup add your..

C# Lock syntax - 2 questions

http://stackoverflow.com/questions/6937342/c-sharp-lock-syntax-2-questions

Lock syntax 2 questions Can I use string as locker in the Lock lock.. Lock syntax 2 questions Can I use string as locker in the Lock lock something Can I do lock without braces if its only one..

When should the volatile keyword be used in C#?

http://stackoverflow.com/questions/72275/when-should-the-volatile-keyword-be-used-in-c

on two different threads without putting a lock in place. Locks guarantee that memory read or modified inside the lock is observed.. For further reading see Understand the Impact of Low Lock Techniques in Multithreaded Apps Sayonara volatile share improve..

Why can't I use the 'await' operator within the body of a lock statement?

http://stackoverflow.com/questions/7612602/why-cant-i-use-the-await-operator-within-the-body-of-a-lock-statement

statement class Async public static async Task IDisposable Lock object obj while Monitor.TryEnter obj await TaskEx.Yield return.. Monitor.Exit this.obj example usage using await Async.Lock padlock await SomethingAsync However this does not work as expected...

How can I intercept all key events, including ctrl+alt+del and ctrl+tab?

http://stackoverflow.com/questions/886076/how-can-i-intercept-all-key-events-including-ctrlaltdel-and-ctrltab

as if the user had pressed Ctrl Alt Del and then selected Lock this computer . To unlock the computer they would then need..

cropping an area from BitmapData with C#

http://stackoverflow.com/questions/9688454/cropping-an-area-from-bitmapdata-with-c-sharp

locking it's bits BitmapData dataOriginal sourceImage.LockBits new Rectangle 0 0 sourceImage.Width sourceImage.Height ImageLockMode.ReadOnly.. Rectangle 0 0 sourceImage.Width sourceImage.Height ImageLockMode.ReadOnly PixelFormat.Format32bppArgb Do analysis get a clone.. 0 0 bmp.Width bmp.Height BitmapData rawOriginal bmp.LockBits new Rectangle 0 0 bmp.Width bmp.Height ImageLockMode.ReadOnly..