Is this code correct or is there any possibility of some random threading deadlocks etc?
Is it a good idea to use static properties and locking together? Or is static property thread-safe anyway?
Private Shared _CompiledRegExes As List(Of Regex)
Private Shared Regexes() As String = {"test1.Regex", "test2.Regex"}
Private Shared RegExSet...
BACKGROUND:
I use an offset into a file and the Filestream lock/unlock menthods to control read/write access. I am using the following code to test if a lock is currently held on the file
try
{
fs.Lock( RESERVED_BYTE, 1 );
fs.Unlock( RESERVED_BYTE, 1 );
rc = 1;
}
catch
{
rc = 0;
}
QUESTION:
My goal is to eliminate the try/c...
I have what looked to me at first glance a very simple problem. I want to be able to obtain a unique key value with a prefix. I have a table which contains 'Prefix' and 'Next_Value' columns.
So you'd think you just start a transaction, get the next value from this table, increment the next value in the table and commit, concatenate the ...
The problem I have is this:
I have a table (just an example) with the following fields:
ID int
Value int
I have a method called IncreaseByFive() which does the following:
method IncreaseByFive(int ID)
{
int value = GetValueFromDB(ID);
value = value + 5;
SaveValueToDB(value, ID);
}
What I want to avoid is the fo...
How can I detect lock/unlock events on the i-phone? Assuming it's only possible for jailbroken devices, can you poin me to the correct api?
...
It's quite common that I need a property in my class which needs to be calculated and cached.
Generally I use a lock and a boolean top check if it's processed or not. Sometimes I do it in accessors.
What's the performance hit of this approach? Is there any better way to it.
Sample Code of my common approach to this:
Sub Main()
...
In any DBMS that's more than half-baked, there is a distinction between a read lock and an update lock. In my multi-threaded C# code, I have, to date, used the lock keyword, but today it came to me that performance in my application would be a lot better if I could make this read vs write distinction in locking; I have many threads that ...
We are using ADO.NET to connect to a SQL 2005 server, and doing a number of inserts/updates and selects in it. We changed one of the updates to be inside a transaction however it appears to (b)lock the entire table when we do it, regardless of the IsolationLevel we set on the transaction.
The behavior that I seem to see is that:
If yo...
I'm currently trying to write a thread-safe logger class. I'm not very familiar with correct design and best practices in this area. Is there a flaw in my code?
public class WriteStuff
{
private readonly StreamWriter m_Writer;
private readonly object m_WriteLock = new object ();
public WriteStuff(String path)
{
m_Writer = File.Cr...
Hi all.
I've got a weird problem. It looks like if my IIS6 locked an application's web.config. If I try to edit it, Windows complains that the web.config is used by another process.
Using Process Explorer I can see that the file is owned by w3wp.exe. Removing the virtual directory and stopping the website wasn't useful at all.
Any idea...
After posting my solution to my own problem regarding memory issues, nusi suggested that my solution lacks locking.
The following pseudo code vaguely represents my solution in a very simple way.
std::map<int, MyType1> myMap;
void firstFunctionRunFromThread1()
{
MyType1 mt1;
mt1.Test = "Test 1";
myMap[0] = mt1;
}
void only...
SQL Server 2000 here.
I'm trying to be an interim DBA, but don't know much about the mechanics of a database server, so I'm getting a little stuck. There's a client process that hits three views simultaneously. These three views query a remote server to pull back data.
What it looks like is that one of these queries will work, but the...
Are the locks from the threading module interchangeable with those from the multiprocessing module?
...
The following program prints:
Entered 3
Entered 4
Wait for Exited messages
Exited 3
Exited 4
Meaning that it cannot acquire an exclusive lock on resource. Why?
public class Worker
{
public void DoIt(object resource)
{
Monitor.Enter(resource);
Console.WriteLine("Entered " + Thread.CurrentThr...
I have to insert some records in a table in a legacy database and, since it's used by other ancient systems, changing the table is not a solution.
The problem is that the target table has a int primary key but no identity specification. So I have to find the next available ID and use that:
select @id=ISNULL(max(recid)+1,1) from subscri...
Hi -
I'm building an application that needs to use a web server like a file system. Specifically, the ideal solution would be:
A server side component that would allow, via HTTP, opening (locking), reading, writing, seeking and truncating one file. I need to be able to lock multiple files simultaneously. I need this to run on any o...
In NHibernate, I want to retrieve an instance, and put an exclusive lock on the record that represents the retrieved entity on the database.
Right now, I have this code:
With.Transaction (session, IsolationLevel.Serializable, delegate
{
ICriteria crit = session.CreateCriteria (typeof (TarificationProfile));
crit.SetLockMode (L...
Hello,
I have a sql server table of licence keys/serial numbers.
Table structure is something like;
[
RecordId int,
LicenceKey string,
Status int (available, locked, used, expired etc.)
AssignedTo int (customerId)
....
]
Through my ASP.NET application, when the user decides to buy a licence clicking the accept button, i need to reserv...
I was recently in an Interview and the tech guy asked me about how to make teh app thread safe.
Well, after explaining the lock() correctly, he said it is not a good idea to have the object as static.
private static readonly object _syncLock = new object();
He claimed the reason is that static makes that object slower for threads to ...
I need to process large image files into smaller image files. I would like to distribute the work to many "slave" servers, rather than tasking my main server with this. I am using Windows Server 2005/2008, C#, and ASP.NET. I have a lot of web application development experience but have not developed distributed systems. I had a notion th...