The object is currently in use elsewhere

T

talljames

Has anyone come across this exception before when dealing with C#
graphics? Have come across some answers that point to the
accelleration control under the screen's
properties/settings/advanced/troubleshooting.

ie the graphics driver.

Other answers include disposing, revalidate.

Any suggestions would be appreciated.

It occurs when I have my GUI is operating fine and I move the Windows
FORM accross the screen. Microsoft report it as a bug, but only for
the PCTABLET.

cheers
 
N

Nicholas Paldino [.NET/C# MVP]

talljames,

Without seeing what it is you are trying to do, or the calls you are
making, it's difficult to offer anything. Can you show a sample of what the
problem is?
 
T

talljames

Bit hard to post the code. But basically I have a clock in a windows
form using the Threading.Timer (as this one is able to operate in a
multithreaded environment). I set the clock off and running. Then I
grab the form with the mouse and move it accross the screen. That's
when the following exception occurs.


An unhandled exception of type 'System.InvalidOperationException'
occurred in system.windows.forms.dll

Additional information: The object is currently in use elsewhere.

Can't seem to track down the error. I have tried it on both Windows
XP and Windows 2000. On the 2000 box I changed the acceleration and
it fixed it. But, this doesn't work with XP.

Any ideas?
 
M

Mabden

talljames said:
Bit hard to post the code. But basically I have a clock in a windows
form using the Threading.Timer (as this one is able to operate in a
multithreaded environment). I set the clock off and running. Then I
grab the form with the mouse and move it accross the screen. That's
when the following exception occurs.


An unhandled exception of type 'System.InvalidOperationException'
occurred in system.windows.forms.dll

Additional information: The object is currently in use elsewhere.

Can't seem to track down the error. I have tried it on both Windows
XP and Windows 2000. On the 2000 box I changed the acceleration and
it fixed it. But, this doesn't work with XP.

Any ideas?

What happens if you stop the clock while you move it? Then you'd have to
jump ahead to the correct time when it is released...
 
T

talljames

Thanks for the posting Mabden. Not much luck with stopping the clock.


The other error I can sometimes get is :

An unhandled exception of type 'System.NullReferenceException'
occurred in system.windows.forms.dll

Additional information: Object reference not set to an instance of an
object.

I am using grfx.save to write some graphics in the background with the
use of drawLine, drawEllipse, drawRectangle, etc then I am restoring
it so that I can reduce the flicker in the clock. Code is very
similar to Petzoid's book "Programming Windows with C#".

When I try and move the windows form it crashes. Have looked at a
snippet of code involving getHdc(), but I shouldn't have to go this
far I don't think.

Any other suggestions would be appreciated.

with regards
 
T

talljames

Thanks for the posting Mabden. Not much luck with stopping the clock.


The other error I can sometimes get is :

An unhandled exception of type 'System.NullReferenceException'
occurred in system.windows.forms.dll

Additional information: Object reference not set to an instance of an
object.

I am using grfx.save to write some graphics in the background with the
use of drawLine, drawEllipse, drawRectangle, etc then I am restoring
it so that I can reduce the flicker in the clock. Code is very
similar to Petzoid's book "Programming Windows with C#".

When I try and move the windows form it crashes. Have looked at a
snippet of code involving getHdc(), but I shouldn't have to go this
far I don't think.

Any other suggestions would be appreciated.

with regards
 
S

Sami Vaaraniemi

talljames said:
Thanks for the posting Mabden. Not much luck with stopping the clock.


The other error I can sometimes get is :

An unhandled exception of type 'System.NullReferenceException'
occurred in system.windows.forms.dll

Additional information: Object reference not set to an instance of an
object. [snip]
Any other suggestions would be appreciated.

One possible cause for the "The object is currently in use elsewhere"
problem is if you access UI elements (forms or other controls) from non-UI
threads. If you are using multi-threaded code, then I'd double check it. One
way to do this is to put this assert as the first line of methods in your UI
classes:

System.Diagnostics.Debug.Assert(!this.InvokeRequired, "InvokeRequired");

Then run your application and if you hit the assert, you know you've got a
threading problem. Or, if you don't hit the assert, then at least you've
ruled out this potential problem.

Regards,
Sami
 
T

talljames

Thanks Sami,

I placed that line of code just after my InitializeComponent(); in the
constructor of my main UI. Yep, and something else happened. I ran
the .NET application, got the clock working and then attempted to
move the windows form on one machine and this is the error I get.

An unhandled exception of type
'System.Runtime.InteropServices.SEHException' occurred in
system.windows.forms.dll

Additional information: External component has thrown an exception.

Will do some web surfing to try and figure out what it means.

thanks again for your posting.

with regards
James
 
T

talljames

Well, I placed a try and catch around the main application.run and
this is what I get. Anyone with a suggestion?

with regards :?

at System.Windows.Forms.UnsafeNativeMethods.CallWindowProc(IntPtr
wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at System.Windows.Forms.NativeWindow.DefWndProc(Message& m)
at System.Windows.Forms.Control.DefWndProc(Message& m)
at System.Windows.Forms.Form.DefWndProc(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ContainerControl.WndProc(Message& m)
at System.Windows.Forms.Form.WmSysCommand(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage(Message&
m)
at System.Windows.Forms.ControlNativeWindow.WndProc(Message&
m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr
hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.CallWindowProc(IntPtr
wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at System.Windows.Forms.NativeWindow.DefWndProc(Message& m)
at System.Windows.Forms.Control.DefWndProc(Message& m)
at System.Windows.Forms.Form.DefWndProc(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ContainerControl.WndProc(Message& m)
at System.Windows.Forms.Form.WmNcButtonDown(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage(Message&
m)
at System.Windows.Forms.ControlNativeWindow.WndProc(Message&
m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr
hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at
System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG&
msg)
at
System.Windows.Forms.ComponentManager.System.Windows.Forms.UnsafeNativeMethods+IMsoComponentManager.FPushMessageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.ThreadContext.RunMessageLoopInner(Int32
reason, ApplicationContext context)
at System.Windows.Forms.ThreadContext.RunMessageLoop(Int32 reason,
ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top