M
Mark S.
Much to my surprised the code below compiled and ran. I just don't know
enough about threading to know for sure if this is too good to be true.
I'm attempting to isolate the Hashtable lock to "row level", the whys aren't
important at this time. Does this code actually do what I want?
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
namespace ConsoleForTesting
{
class testHashTableElementLock
{
public static Hashtable ht = Hashtable.Synchronized(new
Hashtable());
static void Main(string[] args)
{
ht["row1"] = "hello world";
Console.WriteLine(ht["row1"]);
lock (ht["row1"])
{
ht["row1"] = "hi there";
}
Console.WriteLine(ht["row1"]);
Console.ReadLine();
}
}
}
enough about threading to know for sure if this is too good to be true.
I'm attempting to isolate the Hashtable lock to "row level", the whys aren't
important at this time. Does this code actually do what I want?
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
namespace ConsoleForTesting
{
class testHashTableElementLock
{
public static Hashtable ht = Hashtable.Synchronized(new
Hashtable());
static void Main(string[] args)
{
ht["row1"] = "hello world";
Console.WriteLine(ht["row1"]);
lock (ht["row1"])
{
ht["row1"] = "hi there";
}
Console.WriteLine(ht["row1"]);
Console.ReadLine();
}
}
}