|
Hence you must call GoGo() in order to gain access to Go() , thus, provided GoGo() doesn't touch the variables, you've a thread safe method.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
the_jat wrote: but still one thread can(I guess) modify the static variables as the other is executing the if statement
This will not happen as if condition and modifying variable is in the lock. Only one thread will enter into the lock block.
|
|
|
|
|
Thanks for the reply, but
N a v a n e e t h wrote: This will not happen as if condition and modifying variable is in the lock
Did you mean the "modifying variable" or the "statement that modifies the variable"?
Can a lock prevent public static variables of a public class from being modifed by other class running other threads?
Thanks!
|
|
|
|
|
The lock itself only prevents the modification of the variable if every statement that modifies the variable is within a lock block, where the lock is using the same lock object.
|
|
|
|
|
Just an addition.
Think of a house containing your code. The frontdoor has a doorman, who keeps an eye that only one person is in the house at the same time. Inside the house is a box, containing a number (this is the static variable). If everybody who wants to look into the box, or put sth else in the box is using the front door to enter the house everything is okay. But if the house has a backdoor (the architect/programmer didn't pay attention to this) the doorman doesn't know if there is more than one person in the house. So it is possible that two or more persons get to that box and modify the content.
To avoid this, you could assure that there is no backdoor, or you order another doorman (another lock-construct) for the backdoor.
Hope this associativity makes it a bit clearer.
Regards
Sebastian
P.S.: The doorman doesn't know what is inside the house, he is just protecting the front door.
|
|
|
|
|
Thanks a lot!
I finally got it!
|
|
|
|
|
Can I programmatic enumerate running processes?
Thanks
dev
|
|
|
|
|
|
|
thanks mate that's what I was lookin for
dev
|
|
|
|
|
Yes That is possible , you need to use System.Diagnostics Namespace
to use this namespace you should add the following line of code
using System.Diagnostics;
at the top of you application
Then You can use Process.GetProcesses() function to get all the current running process
foreach (Process tempProcess in Process.GetProcesses())
{
listBox1.Items.Add(tempProcess.ToString());
}
This is a small application where i add list of process to a list box on my form , the name of list box is listBox1 .
Let me know if this was what you want .
-Regards
Bharat Jain
bharat.jain.nagpur@gmail.com
|
|
|
|
|
Hello all,
here i am facing some problem in implementing tcp/ip in my web space.
The application is like this.
In the web space, server program has to be executed which listens for the tcp clients. Once we connect to the corresponding server ip and port number from client, server has to accept the client and display the messages sent from the client.
Now the problem is
though i connect from the client by specifying approproiate server ip and port number, server is unable to accept it.
The code i have used in the server program is as follows.
Int32 port = pno;
IPAddress localAddr = IPAddress.Parse("<server ip>");
server = new TcpListener(localAddr, port);
server.Start();
while (true)
{
client = server.AcceptTcpClient();
}
Plese let me know if i am doing any thing wrong here.
I can provide any other information if required.
PS: the same thing in working in LAN
Thanks in advance.
|
|
|
|
|
Hi,
how does you know that the "server is unable to accept" the request? Do you receive an error message? If yes, please provide more information about this.
If it is working within the LAN, maybe it is a firewall problem? Maybe the server is not accepting requests on the port specified.
Regards
Sebastian
|
|
|
|
|
Good Morning guys,
I will need your help on this. i have Backups on a Folder on my C drive on this Path with a .BAK file extension and i want to restore them.
"C:\DATABASE\"
Now i want to go to the Folder and look for all the File names and Display them in the DropDownlist. Am doing this for a ASP.NET Page. i thought it would post it here , because its C# type of question.
Thank you
Vuyiswa Maseko,
Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers."
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.tiyaneProperties.co.za
vuyiswam@its.co.za
|
|
|
|
|
This should do it:
Directory.GetFiles(@"c:\database").ToList().ForEach(n => TheDrowDown.Items.Add(Path.GetFileName(n));
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
hi Guffa
i have not done IO before. So what is the name space ? Does this code supposed to be on one line ? If so i get Errors.
The "Tolist() " is not recognised,
The Foreach not working
.ForEach(n => cmbrestore.Items.Add(Path.GetFileName(n)); <br />
Thanks
Vuyiswa Maseko,
Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers."
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.tiyaneProperties.co.za
vuyiswam@its.co.za
|
|
|
|
|
Vuyiswa Maseko wrote: i have not done IO before. So what is the name space ?
System.IO.
Vuyiswa Maseko wrote: Does this code supposed to be on one line ?
Yes. However, C# is not a line based language, so you can write it in several lines if you like.
Vuyiswa Maseko wrote: The "Tolist()" is not recognised,
The Foreach not working
You need framework 3.5 for those. If you don't have that you have to loop through the names some other way.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
hi Guffa
Thanks , i Found a Solution
DirectoryInfo dir = new DirectoryInfo(@"C:\DATABASES\");
FileInfo[] files = dir.GetFiles();
foreach (FileInfo file in files)
{
cmbrestore.Items.Add(Convert.ToString(file));
}
Thank you
Vuyiswa Maseko,
Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers."
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.tiyaneProperties.co.za
vuyiswam@its.co.za
|
|
|
|
|
You don't need framework 3.5 for ForEach, I guess it's just lambda statement that causes error. anonymous method will work.
|
|
|
|
|
Giorgi Dalakishvili wrote: You don't need framework 3.5 for ForEach
That's right, but you need 3.5 for the ToList method.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
I am trying to add a Arraylist, as a member to another array list.
The problem is, All the members of GroupReqAL are contain the final values of ReqAL. When I debug, first run is fine, in the 2 nd run the ReqAL is added both GroupReqAL[0] and GroupReqAL[1] are set to the latest values of ReqAL and in the 3 rd run GroupReqAL[0] ,GroupReqAL[1],GroupReqAL[2] are set to the latest values of ReqAL... and soon, finally all the members of GroupReqAL containts the latest values of ReqAL. Please advice
int i=0;
int j=0;
ArrayList GroupReqAL=new ArrayList();
ArrayList ReqAL=new ArrayList();
while(i<100)
{
while(j<10)
{
ReqAL.Add(j*i);
j++;
}
GroupReqAL.Add(ReqAL);
i++;
}
|
|
|
|
|
That's because you are adding a reference to the same ArrayList over and over again. If you want to add references to separate ArrayList instances, you have to create a new ArrayList each time.
Unless you are stuck with framework 1 you shouldn't use the ArrayList class at all. Use the generic List<T> class.
Despite everything, the person most likely to be fooling you next is yourself.
modified on Friday, January 16, 2009 6:16 AM
|
|
|
|
|
Hello everyone,
i have button in application when user double click the button the string value show in richtextbox.but how???
here is my code:-
private void MainXmlStart_MouseDoubleClick(object sender, MouseEventArgs e)
{
richTxt.Text = "\nn<book xml:lang="\" en-us\""="">";
richTxt.Focus();
}
Please give me idea...???
where is a mistake...!!
Thanks,
Amit
|
|
|
|
|
Doubleclick event does not fire for button. It is because ControlStyles.StandardDoubleClick property is set to false. In order to fire the double click event, you will need to create your own button by inheriting the button and setting ControlStyles.StandardClick and ControlStyles.StandardDoubleClick to true. This can be done using SetStyle method.
The word "politics" describes the process so well: "Poli" in Latin meaning "many" and "tics" meaning "bloodsucking creatures."
जय हिंद
|
|
|
|
|
hi ,all
a easy case,
year month day
1999 12 2
2000 8 9
2001 9 9
how can i use
listview1.Item.Add(listviewitem) ?
thanks~~~
|
|
|
|