Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Gdi+ Memory Leak >Scrolling text

Gdi+ Memory Leak >Scrolling text

Scheduled Pinned Locked Moved C#
graphicswinformsjsonperformanceannouncement
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    michael cohen
    wrote on last edited by
    #1

    Hey Guys a few days ago i made a custom control that uses GDI+. after playing this control on the screen for 4 hours+ the cpu is getting 50% more Work and Memory Keep Leaking ... after that the text is moving very slow and so on... Here is my code

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.IO;
    using ScreenerViewer.BL.NewsBar;
    namespace ScreenerViewer
    {

    public partial class NewsBar : Control
    {
        //timer 
        Timer t = new Timer();
        //position the text
        int Position;
        //normall mode text
        StringWriter SdisplayNormalMode = null;
        //Flicker Mode Text
        StringWriter SdisplayFlickerMode = null;
        //Separate the Text
        string sSeparatesign = " \* ";
        //Use it for Rest Position
        bool bRestPosition = false;
        // Backround Color For NormalMode
        Brush Backroundbrush = Brushes.Red;
        //Backround Color For Normal mode
        Brush BackroundFlickBrush = Brushes.Yellow;
        //Font color for flickermode
        Brush FontFlickerBrush =Brushes.Red;
        //counter for color change in flicker mode
        int iColorChange = 0;
        //first run of bar
        bool bFirstRun = false;
        
        Font TextFont = new Font(new FontFamily("arial"), 60);
        //Drawing the Point of the text
        PointF TextPoint = new PointF();
        private bool \_bFilckerMode;
        public bool bFilckerMode
        {
            get { return \_bFilckerMode; }
            set { \_bFilckerMode = value; }
        }
    
        public NewsBar()
        {
            
            InitializeComponent();
            this.SetStyle(ControlStyles.DoubleBuffer, true);
            this.SetStyle(ControlStyles.ResizeRedraw, true);
    
            SdisplayNormalMode =  new StringWriter();
            t.Interval = 10;
            t.Enabled = true;
            t.Tick += new EventHandler(t\_Tick);
            Position = 0;
            bFirstRun = true;
            
        }
    
        void t\_Tick(object sender, EventArgs e)
        {
          Position+=2;
          Invalidate();
         // Update();
        }
    
        protected override void OnPaint(PaintEventArgs pe)
        {
            
            if (!this.bFilckerMode)
            {
                   //NormalMode
                    pe.Graphics.FillRectangle(Backroundbrus
    
    L 1 Reply Last reply
    0
    • M michael cohen

      Hey Guys a few days ago i made a custom control that uses GDI+. after playing this control on the screen for 4 hours+ the cpu is getting 50% more Work and Memory Keep Leaking ... after that the text is moving very slow and so on... Here is my code

      using System;
      using System.Collections.Generic;
      using System.ComponentModel;
      using System.Data;
      using System.Drawing;
      using System.Text;
      using System.Windows.Forms;
      using System.IO;
      using ScreenerViewer.BL.NewsBar;
      namespace ScreenerViewer
      {

      public partial class NewsBar : Control
      {
          //timer 
          Timer t = new Timer();
          //position the text
          int Position;
          //normall mode text
          StringWriter SdisplayNormalMode = null;
          //Flicker Mode Text
          StringWriter SdisplayFlickerMode = null;
          //Separate the Text
          string sSeparatesign = " \* ";
          //Use it for Rest Position
          bool bRestPosition = false;
          // Backround Color For NormalMode
          Brush Backroundbrush = Brushes.Red;
          //Backround Color For Normal mode
          Brush BackroundFlickBrush = Brushes.Yellow;
          //Font color for flickermode
          Brush FontFlickerBrush =Brushes.Red;
          //counter for color change in flicker mode
          int iColorChange = 0;
          //first run of bar
          bool bFirstRun = false;
          
          Font TextFont = new Font(new FontFamily("arial"), 60);
          //Drawing the Point of the text
          PointF TextPoint = new PointF();
          private bool \_bFilckerMode;
          public bool bFilckerMode
          {
              get { return \_bFilckerMode; }
              set { \_bFilckerMode = value; }
          }
      
          public NewsBar()
          {
              
              InitializeComponent();
              this.SetStyle(ControlStyles.DoubleBuffer, true);
              this.SetStyle(ControlStyles.ResizeRedraw, true);
      
              SdisplayNormalMode =  new StringWriter();
              t.Interval = 10;
              t.Enabled = true;
              t.Tick += new EventHandler(t\_Tick);
              Position = 0;
              bFirstRun = true;
              
          }
      
          void t\_Tick(object sender, EventArgs e)
          {
            Position+=2;
            Invalidate();
           // Update();
          }
      
          protected override void OnPaint(PaintEventArgs pe)
          {
              
              if (!this.bFilckerMode)
              {
                     //NormalMode
                      pe.Graphics.FillRectangle(Backroundbrus
      
      L Offline
      L Offline
      leppie
      wrote on last edited by
      #2

      michael@cohen wrote:

      after playing this control on the screen for 4 hours+ the cpu is getting 50% more Work and Memory Keep Leaking ... after that the text is moving very slow and so on...

      michael@cohen wrote:

      t.Interval = 10;

      Do the math. 100 repaints a second! 15 frames a second will be more than enough.

      xacc.ide - now with TabsToSpaces support
      IronScheme - 1.0 alpha 4a out now (29 May 2008)

      M 1 Reply Last reply
      0
      • L leppie

        michael@cohen wrote:

        after playing this control on the screen for 4 hours+ the cpu is getting 50% more Work and Memory Keep Leaking ... after that the text is moving very slow and so on...

        michael@cohen wrote:

        t.Interval = 10;

        Do the math. 100 repaints a second! 15 frames a second will be more than enough.

        xacc.ide - now with TabsToSpaces support
        IronScheme - 1.0 alpha 4a out now (29 May 2008)

        M Offline
        M Offline
        Mycroft Holmes
        wrote on last edited by
        #3

        I can't beleive you rabbited through all that code or did the interval issues jump out!

        Never underestimate the power of human stupidity RAH

        L 1 Reply Last reply
        0
        • M Mycroft Holmes

          I can't beleive you rabbited through all that code or did the interval issues jump out!

          Never underestimate the power of human stupidity RAH

          L Offline
          L Offline
          leppie
          wrote on last edited by
          #4

          Mycroft Holmes wrote:

          did the interval issues jump out!

          Mostly, did do a quick scan to see if he was wasting resources, but that was not the case.

          xacc.ide - now with TabsToSpaces support
          IronScheme - 1.0 alpha 4a out now (29 May 2008)

          M 1 Reply Last reply
          0
          • L leppie

            Mycroft Holmes wrote:

            did the interval issues jump out!

            Mostly, did do a quick scan to see if he was wasting resources, but that was not the case.

            xacc.ide - now with TabsToSpaces support
            IronScheme - 1.0 alpha 4a out now (29 May 2008)

            M Offline
            M Offline
            michael cohen
            wrote on last edited by
            #5

            thanx for checking the code. ill try to do as you say...

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups