|
oki, thx
|
|
|
|
|
hi !
does anybody know which of these two methods to synchronize an ArrayList is more efficient?
execute critical code in a lock block:
lock(myArrayList)
{
blabla
}
-or-
define the ArrayList as Syncronized:
myArrayList = ArrayList.Synchronized(unsyncrArrayList);
thanks.
andi
|
|
|
|
|
Andi
There's no difference performance-wise. (Synchronized uses the lock keyword itself.) Sop it boils down to whether you need to specify the actual intent in your code. With
lock(MyArrayList) {
MyArrayList.This();
MyArrayList.That();
MyArrayList.TheOther();
}
you are explicitly stating that, yes, this is threadsafe. Look, there's the lock keyword. With
MyArrayList.This();
MyArrayList.That();
MyArrayList.TheOther();
you are saying, trust me, I've set up MyArrayList to be a Synchronized version of another ArrayList, so this is threadsafe. Maybe the code that sets up the Synchronized version is nearby, so it's obvious (say in a using block).
Of course, if you forget to set up MyArrayList in that way, you've got a bug.
Cheers, Julian
Program Manager, C#
This posting is provided "AS IS" with no warranties, and confers no rights.
|
|
|
|
|
hi !
i have the following problem:
i have -lets say- 3 procedures, which should be called at a given probability:
60 % proc. A
30 % proc. B
10 % proc. C
how can i manage this?
my idea:
r = new Random();
if (r.NextDouble() < 0.6) -> A
if (r.NextDouble() >=0.6 and < 0.9) -> B
if (r.NextDouble() >=0.9 and < 1.0) -> C
in principle this works fine, BUT
is this efficient?
is it exact?
what about the pseudo-random-number-generator in c#?
do you have any suggestions ?!?!?!
THANK YOU !
|
|
|
|
|
It does not work, it has a bug. They way you coded, there will be times where no procedure will be called because you are calling r.NextDouble several times. What you need is to store the number on a local variable, like this:
r = new Random();
double d = r.NextDouble();
if (d < 0.6) -- A
if (d >=0.6 and < 0.9) -- B
if (d >=0.9 and < 1.0) -- C
I hope that you have money because it’s necessary to be practical.
And I hope that at least once a year you put some money in front of you and say "you are mine" just to make clear who owns who. - Victor Hugo
|
|
|
|
|
of course !!!!!
thanks.
|
|
|
|
|
You no with putting some web.config file including below lines:
<configuration>
<system.web>
<authorization>
<deny users="?" />
</authorization>
</system.web>
</configuration>
in some folder, access to that folder is only possible for authenticated users. but this happens only for *.aspx files.
How could we restrict access to for example *.zip files?
|
|
|
|
|
This administrative part, not developer business , simply you have to do it from your windows.
Mazy
No sig. available now.
|
|
|
|
|
hi,
in my app., i have a window form with several labels and groupboxes but no button. i can receive keypress event of that form in my event handler.
however, after added a button the window form, i can't receive KeyPress Event. after deleted it or added another label, it work again!
any help?
thanks,
jim
|
|
|
|
|
hi !
you have to set the KeyPreview-Property of the form to true.
cu
andi
|
|
|
|
|
you also have to
public override bool ProcessKeyPreview( Message msg) {return bProcessed;}
false = did not handle
true = did handle
I'm not an expert yet, but I play one at work. Yeah and here too.
|
|
|
|
|
protected override bool ...
Hi,
AW
|
|
|
|
|
Well your right but i dont see the point. I like javas rule much better on modifiying overriden methods.
nick
I'm not an expert yet, but I play one at work. Yeah and here too.
|
|
|
|
|
Hi,
Is it possible to distribute C# class code in separate files as is possible with C++ classes?
The classes in my application are getting bigger and bigger and distributing different functionalities in separate files could help in managing the code.
Thanks,
|
|
|
|
|
When this happens, it's best to divide the classes up into multiple classes. However, sometimes that's not possible. The current version of C# does not support this, but the next version will support it.
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi
|
|
|
|
|
I am making a control, and in that I need to implement a caret. I do have problems with that simple task.
First I just want to be able to place the caret in the end of a custom text. I do like this:
float xpos = gfx.MeasureString(string, font).Width
g.FillRectangle(System.Drawing.Brushes.Black, xpos - 3, 0, 1, this.Font.Height);
There is a problem with this. If I use 333 as the text, it goes fine, but do I use 1111111191, the caret is being placed maybe 5 - 10 pixels from the last 1. It seems to me that the size of 1 is measured larger than it actually is.
What can I do about this problem? Am I attacking this problem from the wrong angle? Is there any implementation already made?
Gooky
|
|
|
|
|
Add caret sign to the end of displayed string in paint method -or- add it to the string in setting Text property and remove it in getting this property.
Hi,
AW
|
|
|
|
|
That is not really a good solution. Having a carrot inside a word, makes it look a little strange when the carrot blinks.
I found a solution using API calls to old GDI.
Gooky
|
|
|
|
|
How to change the back color of a tool bar control?
Thanks
|
|
|
|
|
How can I host a remote object in IIS?
Mazy
No sig. available now.
|
|
|
|
|
|
Meisi wrote:
5- Use internet services manager to create 2 virtual directories for both above mentioned directories.
THanks Meisi, Of course you don't need put client part under IIS, and I think the server part need some exe file to respond to client, does IIS do it?
Mazy
No sig. available now.
|
|
|
|
|
Mazdak wrote:
I think the server part need some exe file to respond to client
That is the second approach.
Don't forget, that's Persian Gulf not Arabian gulf!
|
|
|
|
|
hehe...and also a configuration file to set some properties like setting chanel,namespace and...
Mazy
No sig. available now.
|
|
|
|
|
How to load an image from a url into a PictureBox.
Thank's
|
|
|
|