|
|
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].)
|
|
|
|
|
Hi,
How do I read data in cells of Excel file by using Microsoft Excel Object 9.0 component?
Please help me.
Thanks
H.Dung
|
|
|
|
|
I guess there is article about Ecxel and C# in CP.
Mazy
No sig. available now.
|
|
|
|
|
|
|
This reads it into a DataTable
public void CreateXLSDataTable( String fileName )
{
//DataTable tb = new DataTable("XLS");
dtXLS = new DataTable();
Excel.Application ExcelObj = null;
ExcelObj = new Excel.Application();
if ( ExcelObj != null )
{
Excel.Workbook empBook = ExcelObj.Workbooks.Open(fileName,0,true,5,"","",true,
Excel.XlPlatform.xlWindows,"\t",false,false,0,true);
Excel.Sheets empSheets = empBook.Worksheets;
Excel.Worksheet empSheet = (Excel.Worksheet)empSheets.get_Item(1);
bool lineValid = true;
int iCount = 1;
while ( lineValid )
{
iCount++;
Excel.Range range = empSheet.get_Range("A"+iCount.ToString(), "X"+iCount.ToString());
System.Array myvalues = (System.Array)range.Cells.Value;
string[] strArray = ConvertToStringArray(myvalues);
if(strArray[0].Equals("") )
{
lineValid = false;
continue;
}
if( iCount != 2 )
{
object[] objArray = strArray;
dtXLS.Rows.Add(objArray);
}
else
{
for(int i=0; i< strArray.Length; i++)
{
dtXLS.Columns.Add(strArray[i]);
}
}
}
}
else
{
Trace.WriteLine("Excel reading Error: could not load the excel file object");
}
ExcelObj.Quit();
ExcelObj = null;
}
private string[] ConvertToStringArray(System.Array values)
{
string[] theArray = new string[values.Length];
for(int i=1; i<=values.Length; i++ )
{
if( values.GetValue(1,i) == null )
theArray[i-1] = "";
else
theArray[i-1] = (string)values.GetValue(1,i).ToString().Trim();
}
return theArray;
}
public DataTable XLS
{
get
{
return dtXLS;
}
}
|
|
|
|
|
lets say I have an
object[] myObjects
once populated from a sqldatareader using getvalues method they can be tons of different ones
how do I use the typeof or different reflections methods to find what exact type it is to compare in a switch statement?
please help, I'm using string comparisons.
nick
|
|
|
|
|
object.GetType() should give you the information you require.
Rocky Moore <><
|
|
|
|
|
foreach (object o in myObjects){
if(o is string ){
...
}
else if(o is int ){
...
}
else if(o is ...){
...
}
...
}
I hope this helps
Don't forget, that's Persian Gulf not Arabian gulf!
|
|
|
|
|
This snippet goes through the collection of objects and does a breakdown by type. This assumes that you have different processes you want applied to the data based on different data types that exist in the collection.
foreach (object item in myObjects)
{
switch (item.GetType())
case typeof(string):
{
...
}
case typeof(int):
{
...
}
...
}
_____________________________________________
The world is a dangerous place. Not because of those that do evil, but because of those who look on and do nothing.
|
|
|
|
|
|
You're welcome.
_____________________________________________
The world is a dangerous place. Not because of those that do evil, but because of those who look on and do nothing.
|
|
|
|
|