Results 1 to 5 of 5

Thread: Object is currently in use elsewhere

  1. #1
    Join Date
    Feb 2009
    Posts
    56

    Object is currently in use elsewhere

    hi,

    I often receive an InvalidOperationException with the message 'Object is currently in use elsewhere' whenever I try to use brushes or pens over multiple threads. However, there are no problems when I perform the same thing by using fonts. Why is this happening using brushes or pens then.....what is the problem ? please suggest some suitable solutions....

  2. #2
    Join Date
    Apr 2008
    Posts
    1,948

    Re: Object is currently in use elsewhere

    I would suggest you to clone each object on different threads since using multiple objects on threads will cause multi-threading which is the main root of this exception error, I think...

  3. #3
    Join Date
    May 2008
    Posts
    2,012

    Re: Object is currently in use elsewhere

    I was also getting the same InvalidOperationException when I used to close my forms. My solution was to make sure that all my controls got disposed in the Dispose method of my UserControls. Here's the code :

    Code:
    protected override void Dispose(bool disposing)
             {
               if (disposing)
               {
                 foreach (Control control in this.Controls)
                 {
                   IDisposable disposable = control as IDisposable;
                   if (disposable != null)
                   {
                     disposable.Dispose();
                   }
                 }
                 if (components != null)
                 components.Dispose();
                }
               base.Dispose(disposing);
             }

  4. #4
    Join Date
    Apr 2008
    Posts
    2,005

    Re: Object is currently in use elsewhere

    I don't know whether someone has got the perfect solution to this problem yet....I would simply suggest you that - do not use multi-threading....

  5. #5
    Join Date
    Oct 2005
    Posts
    2,393

    Re: Object is currently in use elsewhere

    This error normally occurs while using automatic double buffering on
    .NET version 1.1. It doesn't mean that it doesn't exists on the other versions.

    You can handle the exception by perform manual double buffering..

Similar Threads

  1. Replies: 6
    Last Post: 06-06-2011, 01:34 AM
  2. Replies: 3
    Last Post: 08-01-2011, 06:20 AM
  3. Differents between object and static object
    By Sarfaraj Khan in forum Software Development
    Replies: 5
    Last Post: 29-01-2010, 01:11 PM
  4. Object reference not set to an instance of an object
    By KAIRU26 in forum Software Development
    Replies: 3
    Last Post: 05-09-2009, 08:14 PM
  5. Object test = new Object() <-- Java, best way in C++
    By ADISH in forum Software Development
    Replies: 3
    Last Post: 25-10-2008, 02:32 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,018,466.83121 seconds with 16 queries