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. Cursor Dispose Problem

Cursor Dispose Problem

Scheduled Pinned Locked Moved C#
help
2 Posts 2 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.
  • K Offline
    K Offline
    Keshav V Kamat 0
    wrote on last edited by
    #1

    Consider my code below Cursor m_OldCursor; void OnCursorChanged(object sender, EventArgs e) { if(m_OldCursor != null) { m_OldCursor.Dispose(); } m_OldCursor = new Cursor(this.Cursor.CopyHandle()); } void ProcessMouseMove(EventArgs e) { // m_OldCursor is used here too. // hence cannot be declared everytime in // OnCursorChanged. } I know it is wrong to use a object after it is disposed. but every single time the CopyHandle() method is invoked, it creates a handle. since there is a restriction on the number of handles that windows can manage, i need to dispose this handle after its use. if not then the application will crash. If instead of Cursor, it was a control then i could have used the DestroyHandle property. Could you suggest me any other way to do the same. thanks in advance.

    Keshav Kamat :) India

    L 1 Reply Last reply
    0
    • K Keshav V Kamat 0

      Consider my code below Cursor m_OldCursor; void OnCursorChanged(object sender, EventArgs e) { if(m_OldCursor != null) { m_OldCursor.Dispose(); } m_OldCursor = new Cursor(this.Cursor.CopyHandle()); } void ProcessMouseMove(EventArgs e) { // m_OldCursor is used here too. // hence cannot be declared everytime in // OnCursorChanged. } I know it is wrong to use a object after it is disposed. but every single time the CopyHandle() method is invoked, it creates a handle. since there is a restriction on the number of handles that windows can manage, i need to dispose this handle after its use. if not then the application will crash. If instead of Cursor, it was a control then i could have used the DestroyHandle property. Could you suggest me any other way to do the same. thanks in advance.

      Keshav Kamat :) India

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      Hi, two comments: 1. you should not try to dispose of cursors that you did not create yourself; that's every Cursor you get from the Cursors class (the system created those, it will dispose of them too when appropriate, and maybe never !) 2. who is changing the cursor ? cant you do that with a simple method, something like (inside your form class):

      public static void SetCursor(Cursor newCursor) {
      Cursor oldCursor=Cursor;
      Cursor=newCursor;
      oldCursor.Dispose();
      }

      no handles involved ! Hope this helps.

      Luc Pattyn


      try { [Search CP Articles] [Search CP Forums] [Forum Guidelines] [My Articles] } catch { [Google] }


      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