|
oh my god, i'm gonna go ape sh*t!
if(done)
do1
else
do2
what number does done have to be to do1?
In C what number does done in the if statement have to be to give a true condition
|
|
|
|
|
I think if done is 0 then (bool )done is false otherwise it's true.
but, why don't you use bool data type?
private bool <code>done</code>;
done = true;
if(<code>done</code>)
do1;
else
do2;
Don't forget, that's Persian Gulf not Arabian gulf!
|
|
|
|
|
Lesson learnt from Perl:
It is easier to define "false" than "true": 0 (zero) and null are "false", everything else is true.
Olorin,
YAPPTH
|
|
|
|
|
int done;
...
if (Convert.ToBoolean(done))
break;
α.γεεκ Fortune passes everywhere. Duke Leto Atreides
|
|
|
|
|
Why keep it an int at all?
bool done = false;
...
if( done )
break; C doesn't have a concept of a boolean so you had to use some other data type to represent one, most code uses an int to hold a boolean value. C++ has bool datatype, but since the Win32 API is C based you typically don't use it favoring an int or the #defined BOOL .
Like C++, C# has a bool data type, unlike C++ though there isn't any legacy code to be aware of so you should use it whenever necessary.
[edit]And unlike C/C++, the bool datatype has a true/false value instead of a non-zero/zero value. So you need to assign true to done instead of a 1.
James
"I despise the city and much prefer being where a traffic jam means a line-up at McDonald's"
Me when telling a friend why I wouldn't want to live with him
|
|
|
|
|
The suggestion above to use a bool is the best.
The suggestion to cast the int to a bool is silly.
By definition, a int is "true" if it does NOT equal zero. Thus you should always test against the false situation. The correct syntax of your two choices is:
if (0 != done)<br />
break;
This syntax should also be used in C# (if you don't use bool.)
|
|
|
|
|
how to detect that I just press Ctrl+Key
I was try with code :
<br />
privated void myInput_KeyDown(object sender,KeyEventArgs e)<br />
{<br />
if (e.KeyCode==(Keys.G & Keys.Control)<br />
{<br />
}<br />
}<br />
but It not run
please help me, thanks
|
|
|
|
|
Can anyone show me how to fill this figure with a blue color?
System.Drawing.Graphics formGraphics = null;
System.Drawing.Pen myPen;
formGraphics = pictureBox7.CreateGraphics();
myPen = new System.Drawing.Pen(System.Drawing.Color.Black,1);
formGraphics.DrawLine(myPen, 4, 4, 50, 4);
formGraphics.DrawLine(myPen, 4, 4, 4, 100);
formGraphics.DrawLine(myPen, 50, 4, 50, 100);
formGraphics.DrawLine(myPen, 4, 100, 27, 120);
formGraphics.DrawLine(myPen, 50, 100, 27, 120);
Maybe with the FillPolygon method.
|
|
|
|
|
Point[] points = {
new Point(4, 4),
new Point(50, 4),
new Point(50, 100),
new Point(27, 120),
new Point(4, 100),
new Point(4, 4)};
SolidBrush brush = new SolidBrush(Color.Blue);
e.Graphics.FillPolygon(brush, points, FillMode.Alternate);
e.Graphics.DrawLines(myPen, points);
|
|
|
|
|
WiB:
Thanks. It works perfekt.
How do you know in which order to put the Points??
Eks:
Point[] points = {
new Point(4, 4),
new Point(50, 4),
new Point(50, 100),
new Point(27, 120),
new Point(4, 4),
new Point(4, 100)};
Won't fill the figure correkt.
|
|
|
|
|
Because there is a rule:
You put points in the same order like it would be if you draw figure by hand without break:
you start from first point in array, draw line until second, after draw line from second point to third and so on to the last point.
And normally I start and finish points array with the same point, but it's not allways necessary.
|
|
|
|
|
|
WiB:
Is it possible to make the mouse cursor = Cursors.Hand
if the the user point the mouse inside my figure ?
formGraphics.DrawLine(myPen, 4, 4, 50, 4);
formGraphics.DrawLine(myPen, 4, 4, 4, 100);
formGraphics.DrawLine(myPen, 50, 4, 50, 100);
formGraphics.DrawLine(myPen, 4, 100, 27, 120);
formGraphics.DrawLine(myPen, 50, 100, 27, 120);
|
|
|
|
|
1). In OnPaint :
Point[] points = {
new Point(4, 4),
new Point(50, 4),
new Point(50, 100),
new Point(27, 120),
new Point(4, 100),
new Point(4, 4)};
GraphicsPath path = new GraphicsPath();
path.AddLines(points);
Region reg = new Region(path);
bounds = reg.GetBounds(e.Graphics);
2). Override OnMouseMove method as follow:
protected override void OnMouseMove(System.Windows.Forms.MouseEventArgs e)
{
if (bounds.Contains(e.X, e.Y))
this.Cursor = Cursors.Hand;
else this.Cursor = Cursors.Default;
base.OnMouseEnter(e);
}
RectangleF bounds is global
This is if you want to draw a shape on a form.
If your shape is a control on the form, you should do it by another way.
PS: Because variable bounds you inisialize only once, you should do it, for example, in constructor or you may keep it in OnPaint but make sure that you initialize it once (performance!).
"...hasn't really been well accepted ... as the ratings tell us so far " - Nishant S
|
|
|
|
|
I'm am developing a user control with some properties in it. Some of these properties, I only want them to be accessible in codes, and not visible in the property window when the control is added to the form.
For Example, if I have a property Name , this:
Control.Name
is ok, but I don't want the Name property visible in the Property Window
Does anyone have any ideas on how to achieve this? Any help would be welcome.
Nick Seng (the programmer formerly known as Notorious SMC)
God, I pity me! - Phoncible P. Bone
|
|
|
|
|
Put this above your property:
[Browsable(false)]
"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 found the solution 10 minutes after I posted that. That'll teach me to stop giving up so fast.
But thanks on the prompt answer.
Nick Seng (the programmer formerly known as Notorious SMC)
God, I pity me! - Phoncible P. Bone
|
|
|
|
|
Hello,
Suppose to have a 4 processors system.
It is better to have 32 working threads or 8 groups of 4 working threads to do the same job.
In the first case I can ignore the number of processors because the work it is splitted equally on everyone. In the second I have to take care of it but maybe the OS is less involved in continually switching from thread to thread...
Any other consideration to help me decide?
Thanks a lot,
Alberto Bencivenni
www.devDept.com
|
|
|
|
|
Alberto
Any other considerations? Sure: what are the threads doing, do the threads interact with other (operating system) processes and threads, are you going to be implementing a thread pool (that is, sharing lots of thread-like activity amongst a small set of threads), how are you implementing synchronization, how many objects need synchronization, do the threads interface with the UI thread, etc, etc.
What I'm trying to get at is this. The question as posed has no right or wrong answer. To find out your answer, you need to write the app, or as much of the app as makes sense, and then profile it (that is run it and tweak it) in the environment you want. Worrying too much about fine details like how can you extract as much performance from a four processor system versus, say, a two processor system when you don't have the actual code is putting the cart before the horse. Writing performant multithreaded apps tends to be more about how efficient and well-written your inter-threadd communication is set up than anything else.
Also, in my experience, trying to second-guess the operating system by forcing some threads onto some CPU and others onto another, could do more harm than good.
Cheers, Julian [MSFT]
Program Manager, C#
This posting is provided "AS IS" with no warranties, and confers no rights.
|
|
|
|
|
Julian,
I have - lets say 16 - working threads that are doing a very intensive task and 1 UI threads that waits for them. I work on a double Intel XEON processor workstation.
After waiting this 16 workers (with the WaitAll on 16 ManualResetEvent handles) I sort the results alter the data and start again. In 2 words a GA algorithm.
Threads are completely indipendend one from the other and don't interact with the UI thread.
In my opinions should be better to detect the number of processor (suppose 2) and do 8 job on each processor (this would mean 1 UI thread, 2 workers and 2 MaualResetEvent for synchronization). The other option is to start all the 16 threads and leave the OS to split the work between available processors. I did not consider the Threadpool because I read somewere that it is not good for very intensive tasks...
Am I right?
Do you know any article that specifically talk about these matters?
Thanks a lot,
Alberto Bencivenni
www.devDept.com
|
|
|
|
|
I don't know. The best answer I can give is: write it to not "know" about the number of processors. This is the simplest code you could write: you're going to let the OS do all the scheduling work. After all the OS is going to be context-switching under you anyway to service the network, do file IO, do whatever.
If the performance isn't all it's cracked up to be, now add some moderately complex code to identify how many processors there are, how to split up the total work between processors, etc. Run it and profile. Tweak. Run it and profile. Rinse and repeat. I would doubt that you'd make much difference for the amount of work it will take you. I would hazard a guess that improving the algorithm that's doing the work will get you more bang for your coding buck.
The threadpool is designed to obviate the need to continually create OS threads, an expensive process. That's all. It makes no difference to the speed of execution of code in the thread.
References, wow. Not off the top of my head, no, sorry. Certainly I don't know of any in the C#/.NET world.
Cheers, Julian
Program Manager, C#
This posting is provided "AS IS" with no warranties, and confers no rights.
|
|
|
|
|
I seem to recall that the optimal number of active worker threads per CPU is two. If those threads will be waiting, you will, of course, need a larger thread pool.
To scale correctly, you should detect the number of CPUs and act accordingly, but unless you are doing something very specialized (like assigning a thread to a CPU) I'd suggest using a single pool.
Of course, you'd want to empirically test any proposed solution to the extent possible. (I can't actually emphasize this enough. I've been surprised more than once by actual performance in heavily multi-threaded apps.)
|
|
|
|
|
Interesting, in my work project, I've been assuming something like a minimum of 10 threads and an upper bound of 25 threads. (I've been using Mike Woodring's ThreadPool, which seems far more superior to System.Threading.ThreadPool.) I'm worried that it's overloading the CPU... My project does a lot of work with collecting a bunch of Web pages and parsing them. Some time is spent waiting for a page to be received, but a lot more is spent processing/scraping the pages. Perhaps I'll try a lower minimum and perhaps a lower maximum.
|
|
|
|
|
Hello Joe,
So, we can say that to improve the application performances it is better to use the smallest number of thread that keep processors at 100% of usage?
Thanks a lot,
Alberto Bencivenni
www.devDept.com
|
|
|
|
|
For optimal performance you want to minimize context switches, so the fewest number of threads using the maximum amount of CPU is the best. (Realize, of course, that if your threads are using up their entire slice, you will see serious system degredation from other, especially low priority, processes [like the GUI].)
|
|
|
|
|