Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6136985
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:40:16+00:00 2026-05-23T17:40:16+00:00

I have a System.Windows.Controls.Canvas on to which I programatically place a System.Windows.Shapes.Polygon: private Canvas

  • 0

I have a System.Windows.Controls.Canvas on to which I programatically place a System.Windows.Shapes.Polygon:

private Canvas mMainCanvas = new Canvas();
private Polygon mHistogram = new Polygon();

Later on, I update the polygon with a very large number of events (~1,000,000 or so). I have been trying to make this as fast and efficient as possible (a struggle in its self). My latest attempt was to accumulate the values into a PointCollection and periodically re-set the collection of the Polygon (mHistogram):

int i = 10000;
PointCollection mPc = new PointCollection(256);
double y;
Point p;

private void EventProcessor( int bin ) {
    if (0 < i--) {
        p = mPc[bin];
        y = p.Y + 1;
        p.X = p.X;
        p.Y = y;
        mPc[bin] = p;
        if (mMainCanvas.Height < p.Y)
            mMainCanvas.Height = p.Y;
    }
    else {
        i = 10000;
        mHistogram.Points = new PointCollection( mPc ); /* This works if mPc
                                                           is a PointCollection.
                                                           It does not work if 
                                                           mPc is a Point[]
    }
}

This seems to work OK, albeit still not fast enough. So, I changed the type of mPc from a PointCollection to a simple array of Points (Point[]), hoping this would make access a little faster. However, when I do this, my Polygon (mHistogram) fails to update at all.

This is baffling to me. I create a new PointCollection from an IEnumerable (mPc) which should create a new PointCollection that behaves just like any other PointCollection. Why does it behave differently when created with an Array (Point[])?

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T17:40:17+00:00Added an answer on May 23, 2026 at 5:40 pm

    The problem you describe seems unlikely and is probably related to another issue with your code. Looking at this simple test, you can verify that the same collections are in fact created:

    PointCollection collection1 = new PointCollection(new Point[] { new Point(1, 1), new Point(2, 2) });
    PointCollection collection2 = new PointCollection(collection1);
    for (int i = 0; i < collection2.Count; i++) {
        if (collection1[i] != collection2[i])
            throw new InvalidOperationException();
    }
    

    As for the assignment to the Points property, the Polygon wouldn’t care how the PointsCollection was created.

    Both these pieces of code produce the same results:

    poly.Points = new PointCollection(new Point[] {
        new Point(100, 100),
        new Point(200, 200)
    });
    

    and:

    var coll = new PointCollection();
    coll.Add(new Point(100, 100));
    coll.Add(new Point(200, 200));
    poly.Points = new PointCollection(coll);
    

    Keep in mind that the following are different:

    var collection = new PointCollection(256);
    var array = new Point[256];
    

    The collection contains 0 items, but has space to hold 256 preallocated. The array contains 256 items and will only ever have space to hold 256 items.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a current system which is build as a Windows Application, and does
I am trying to subclass System.Windows.Controls.DataGrid in order to add special commands to which
I have written a control in C# that derives from System.Windows.Forms.Control. I have added
I have a System.Windows.Forms.TreeView docked inside a panel. I am setting a node selected
Consider System.Windows.Forms.StatusStrip . I have added a StatusStrip to my Windows Forms application, but
I have a file called hellowf.cs class MyFirstApp { static void Main() { System.Windows.Forms.MessageBox.Show(Hello,
I have a little demonstration below of a peculiar problem. using System; using System.Windows.Forms;
( .NET 2.0, System.Windows.FormsDataGridView and DataTable ) I have 1 datagrid connected to 1
I have a windows service that runs various system monitoring operations. However, when running
Firstly let me clarify (if the title wasn't clear enough): I'm discussing System.Windows.Controls.DataGrid from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.