|
George_George wrote: Why using internal private object as lock object will reduce chance of deadlock compared with using this object? Could you describe a scenario please?
Well, if you use a private object then nothing outside the class can access the object. That means that you have full control within the class of how instances of the class are synchronised.
If you use "this", and other code uses the reference to the same object then they can interfere with each other. There isn't much you can do to defend yourself from code that you have not written and have no control over.
|
|
|
|
|
Thanks Colin,
I can understand the situation you described above. But could you show by example why in the similar situation, using this object other than using private member as lock object will be more prone to cause deadlock please?
A sample will make everything clear.
regards,
George
|
|
|
|
|
How can I create a subclass from a base class by just just inputting the name of the subclass I want to create? I think this uses System.Reflection. Need a working code. Thanks.
modified on Saturday, March 22, 2008 9:09 AM
|
|
|
|
|
Use Assembly.CreateInstance[^] to create an instance of a type based on a string representing the name of the type.
Paul Marfleet
"No, his mind is not for rent
To any God or government"
Tom Sawyer - Rush
|
|
|
|
|
how to search particular word from the site using .net with c#
|
|
|
|
|
The most obvious way would be to use google.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Thank you .but I want do to our own search from my own web site. It is possible.
|
|
|
|
|
Yes, of course it is. You'd have to have no dynamic pages, and store all your pages in a SQL Server database. Or, you'd have to write your own search engine that indexes all your pages.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Hello everyone,
What means "the synchronizing object can double as the object it's protecting" in below statements about synchronization object choosing?
I quote the whole paragraph,
http://www.albahari.com/threading/part2.html
--------------------
Choosing the Synchronization Object
Any object visible to each of the partaking threads can be used as a synchronizing object, subject to one hard rule: it must be a reference type. It’s also highly recommended that the synchronizing object be privately scoped to the class (i.e. a private instance field) to prevent an unintentional interaction from external code locking the same object. Subject to these rules, the synchronizing object can double as the object it's protecting, such as with the list field below:
class ThreadSafe {
List <string> list = new List <string>();
void Test() {
lock (list) {
list.Add ("Item 1");
...
--------------------
thanks in advance,
George
|
|
|
|
|
You have a synchronising object, the object used in the lock statement. You also have the object you are protecting with the lock. The statement means that the object you use in the lock statement can be the same as the object you are protecting.
Does that help?
|
|
|
|
|
Thanks Colin!
I think you metn the "list" object is the synchronising object. But what do you mean "the object you are protecting with the lock", you mean also the list obejct which we are going to make it thread-safe?
regards,
George
|
|
|
|
|
George_George wrote: I think you metn the "list" object is the synchronising object
In the example the "list" object is the synchronising object.
George_George wrote: But what do you mean "the object you are protecting with the lock", you mean also the list obejct which we are going to make it thread-safe?
In the example, yes, it will be the list object also.
The example was showing that the object used in the lock, the list, can be the same as the object that is being protected, which is again the list.
|
|
|
|
|
Thanks Colin,
Question answered.
regards,
George
|
|
|
|
|
i want search word in particular web address,so i want to use UltimateSearchInput button,but i didnot know how to use. if u know the code replay to me...
|
|
|
|
|
Hello everyone,
From the sample,
http://www.albahari.com/threading/part2.html
Do you know what means "A thread can block only on the first, or outermost lock."?
I quote the related context below as well.
--------------------
Nested Locking
A thread can repeatedly lock the same object, either via multiple calls to Monitor.Enter, or via nested lock statements. The object is then unlocked when a corresponding number of Monitor.Exit statements have executed, or the outermost lock statement has exited. This allows for the most natural semantics when one method calls another as follows:
static object x = new object();
static void Main() {
lock (x) {
Console.WriteLine ("I have the lock");
Nest();
Console.WriteLine ("I still have the lock");
}
Here the lock is released.
}
static void Nest() {
lock (x) {
...
}
Released the lock? Not quite!
}
A thread can block only on the first, or outermost lock.
--------------------
thanks in advance,
George
|
|
|
|
|
George_George wrote: Do you know what means "A thread can block only on the first, or outermost lock."?
It means that when it encounters the first lock (or outermost lock) the thread blocks others from accessing the object that is locked.
An individual thread can lock an object as many times as it likes, but it only locks on the first occurrence.
|
|
|
|
|
Thanks Colin,
Two more comments,
1.
Colin Angus Mackay wrote: It means that when it encounters the first lock (or outermost lock) the thread blocks others from accessing the object that is locked.
Even if the thread can not acquire the outermost lock, it will block other thread from accessing the lock object to try to lock?
2.
Colin Angus Mackay wrote: An individual thread can lock an object as many times as it likes, but it only locks on the first occurrence.
It is a typo, "only locks on the first occurrence" should be "only blocks on the first occurrence"?
regards,
George
|
|
|
|
|
George_George wrote: Even if the thread can not acquire the outermost lock, it will block other thread from accessing the lock object to try to lock?
It hast to aquire the lock first. If it can't aquire the lock, it can't block.
George_George wrote: It is a typo
Yes. You are correct.
|
|
|
|
|
Thanks Colin,
Question answered. Cool!!
regards,
George
|
|
|
|
|
Hi
How to Install and Configure CRM 3.0 SDK Problem in Vs.Net 2003 ?
please give me an article that explain perfectly.
thanks
|
|
|
|
|
Try here[^].
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Hi
thanks for reply
i tried your suggestion, but i don't found any useful topic with match with my aim in this link[^]
can anyBody help me ?
|
|
|
|
|
Hi
how to pass textbox value from one form to other form in window application
+c# .If any one knows this help me with code i'm new to window application
Thanks and regards
suman
|
|
|
|
|
Lots of different ways, but you could expose a property on one of the forms like:
public string TheValue
{
get { return theTextBox.Text; }
set { theTextBox.Text = value; }
}
Your other form can set TheValue using code like chee:
form2.TheValue = "stuff";
form2 would be an instance of your "other form" which has already been created, of course.
- S
50 cups of coffee and you know it's on!
|
|
|
|
|
You can also pass it to a session variable and u can retrive the values in the form u needed.
|
|
|
|