Questions tagged [synclock]

SyncLock is the VB.NET keyword for its locking statement.

SyncLock is the VB.NET keyword for its locking statement, allowing any non-structure type to be locked by a transaction.

46 questions
23
votes
3 answers

How accurate is the GPS Clock?

In my company we do have critical systems that require an accurate time. As so, we have an NTP server appliance with an outdoor GPS antenna that receives the time from the GPS satellites. My questions are: How accurate is the time clock? Is it…
Andre
  • 598
  • 1
  • 7
  • 18
9
votes
5 answers

Why use SyncLocks in .NET for simple operations when Interlocked class is available?

I've been doing simple multi-threading in VB.NET for a while, and have just gotten into my first large multi-threaded project. I've always done everything using the Synclock statement because I didn't think there was a better way. I just learned…
SqlRyan
  • 33,116
  • 33
  • 114
  • 199
6
votes
2 answers

SyncLock on Write? Read? Or both?

Suppose I have a byte array, Private Data as Byte(). This array is private within a class. The class provides public functions for reading and writing to Data. This class can be accessed by multiple threads, so I want to avoid a situation where…
Brad
  • 159,648
  • 54
  • 349
  • 530
5
votes
3 answers

What is the difference between `Synclock syncroot` and `SyncLock Me`?

vb.Net multithreading question: What is the difference between SyncLock syncRoot ''# Do Stuff End SyncLock -and- SyncLock Me ''# Do Stuff End SyncLock
Vivian River
  • 31,198
  • 62
  • 198
  • 313
5
votes
1 answer

Should I double check before and after locking a list?

I have an in-application service which allows me to feed it messages from various sources, which will be put into a simple list. The service, running in its own thread, will, periodically, process all messages in the list into various files; one…
Randy Dodson
  • 252
  • 2
  • 10
4
votes
2 answers

Why is SyncLock not working here?

I am working on a class library that will provide asynchronous communication to CLR applications. There are asynchronous reads (BeginRead) on SslStream with a single callback routine shared by multiple streams. I don't want the callbacks to be…
Luc VdV
  • 1,088
  • 9
  • 14
4
votes
2 answers

Is it a bad idea to put frequent file I/O operations within a SyncLock block?

Say I have some code that does this: Public Function AppendToLogFile(ByVal s As String) As Boolean Dim success As Boolean = True Dim fs As IO.FileStream = Nothing Dim sw As IO.StreamWriter = Nothing Static LogFileLock As New…
Dan Tao
  • 125,917
  • 54
  • 300
  • 447
3
votes
2 answers

Difference between Synclock and WaitOne

I've used a thread managed waiter. SyncLock http://msdn.microsoft.com/en-us/library/3a86s51t%28v=vs.71%29.aspx But now, I wanted to have a timeout and found the…
Nasenbaer
  • 4,810
  • 11
  • 53
  • 86
3
votes
2 answers

Should synclock be used on properties?

I have been reading around and am getting conflicting answers on whether I should or should not use synclock on properties. I have a multi-threaded application that needs to get/set properties across threads on instance objects. It is currently…
Netpuppy
  • 33
  • 1
  • 3
3
votes
1 answer

How does lock(syncRoot) make sense on a static method?

The following code is excerpted from the (Windows Identity Foundation SDK) template that MS uses to create a new Security Token Service Web Site. public static CustomSecurityTokenServiceConfiguration Current { get { var key =…
Vivian River
  • 31,198
  • 62
  • 198
  • 313
3
votes
1 answer

Is SyncLock reetrant?

I have the following code in a class that manages refreshing some object automatically that also allows you to manually refresh. I want to make it thread-safe. Public Function ForceRefresh() As Foo DoRefresh() ResetTimer() Return…
Jeff B
  • 8,572
  • 17
  • 61
  • 140
3
votes
1 answer

SyncLock on SyncRoot

I have created a synchronized queue and am using SyncLock on the SyncRoot property of that queue when I invoke the Enqueue/Dequeue methods. The methods are invoked from instances of standard producer/consumer classes. Is that a proper use of the…
user79755
  • 2,623
  • 5
  • 30
  • 36
2
votes
1 answer

.NET multithreading Synclock vs Monitor

I'm building a slightly more efficient connection pool for a multi threaded service I'm writing to talk between my service and its SQL database. basically boiled down, I've got this code in my class: Public Class DBMC Private Connections As New…
Jrud
  • 1,004
  • 9
  • 25
2
votes
3 answers

SyncLock on null object

Is there simple way to SyncLock an object that can be null? And before you ask for it, yes, I know that it isn't logical to perform a SyncLock on a null variable. However, that would simplify my code because right now, I have no choice but to…
The_Black_Smurf
  • 5,178
  • 14
  • 52
  • 78
2
votes
3 answers

SyncLock on two objects

Suppose I have two objects a and b. I want to SyncLock on both objects. Is this feasible? Can it be done by nested SyncLock statements? What are the dangers of such an operation? Edit Perhaps I should ask, how can one refactor to avoid deadlocks?
User48765902
  • 361
  • 1
  • 4
  • 7
1
2 3 4