473,753 Members | 6,232 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

The object is currently in use elsewhere

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

Nov 16 '05 #1
9 11106
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?

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"talljames" <ta*******@hotm ail-dot-com.no-spam.invalid> wrote in message
news:41******** **@Usenet.com.. .
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

Nov 16 '05 #2
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.Invalid OperationExcept ion'
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?

Nov 16 '05 #3
"talljames" <ta*******@hotm ail-dot-com.no-spam.invalid> wrote in message
news:41******** @Usenet.com...
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.Invalid OperationExcept ion'
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...

--
Mabden

Nov 16 '05 #4
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.NullRef erenceException '
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 "Programmin g 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

Nov 16 '05 #5
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.NullRef erenceException '
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 "Programmin g 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

Nov 16 '05 #6
"talljames" <ta*******@hotm ail-dot-com.no-spam.invalid> wrote in message
news:41******** @Usenet.com...
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.NullRef erenceException '
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.Diagnost ics.Debug.Asser t(!this.InvokeR equired, "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
Nov 16 '05 #7
Thanks Sami,

I placed that line of code just after my InitializeCompo nent(); 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 .InteropService s.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

Nov 16 '05 #8
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.UnsafeNat iveMethods.Call WindowProc(IntP tr
wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at System.Windows. Forms.NativeWin dow.DefWndProc( Message& m)
at System.Windows. Forms.Control.D efWndProc(Messa ge& m)
at System.Windows. Forms.Form.DefW ndProc(Message& m)
at System.Windows. Forms.Control.W ndProc(Message& m)
at System.Windows. Forms.Scrollabl eControl.WndPro c(Message& m)
at System.Windows. Forms.Container Control.WndProc (Message& m)
at System.Windows. Forms.Form.WmSy sCommand(Messag e& m)
at System.Windows. Forms.Form.WndP roc(Message& m)
at System.Windows. Forms.ControlNa tiveWindow.OnMe ssage(Message&
m)
at System.Windows. Forms.ControlNa tiveWindow.WndP roc(Message&
m)
at System.Windows. Forms.NativeWin dow.DebuggableC allback(IntPtr
hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows. Forms.UnsafeNat iveMethods.Call WindowProc(IntP tr
wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at System.Windows. Forms.NativeWin dow.DefWndProc( Message& m)
at System.Windows. Forms.Control.D efWndProc(Messa ge& m)
at System.Windows. Forms.Form.DefW ndProc(Message& m)
at System.Windows. Forms.Control.W ndProc(Message& m)
at System.Windows. Forms.Scrollabl eControl.WndPro c(Message& m)
at System.Windows. Forms.Container Control.WndProc (Message& m)
at System.Windows. Forms.Form.WmNc ButtonDown(Mess age& m)
at System.Windows. Forms.Form.WndP roc(Message& m)
at System.Windows. Forms.ControlNa tiveWindow.OnMe ssage(Message&
m)
at System.Windows. Forms.ControlNa tiveWindow.WndP roc(Message&
m)
at System.Windows. Forms.NativeWin dow.DebuggableC allback(IntPtr
hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at
System.Windows. Forms.UnsafeNat iveMethods.Disp atchMessageW(MS G&
msg)
at
System.Windows. Forms.Component Manager.System. Windows.Forms.U nsafeNativeMeth ods+IMsoCompone ntManager.FPush MessageLoop(Int 32
dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows. Forms.ThreadCon text.RunMessage LoopInner(Int32
reason, ApplicationCont ext context)
at System.Windows. Forms.ThreadCon text.RunMessage Loop(Int32 reason,
ApplicationCont ext context)
at System.Windows. Forms.Applicati on.Run(Form mainForm)

Nov 16 '05 #9
Yes, after hours of tracking down the bug, it looks like a thread and
main UI problem. I wish that Microsoft had an easier solution to
this rather than have to create invokes. I ended up having to create
an event and then subscribe to that event in the main form and then
run the invoke as just placing a delegate and invoke solution did not
do the trick in this case.

Also, the .NET Invoke method does not like to be placed in a static
method.

This error did not leave me with any clues as to where it came from ie
no method names from my code or line numbers. Another thing that
Microsoft could have in the debugger, if possible.

So, what I thought was perhaps a DataGrid/Table on a form problem
turned out to be a thread problem after all. Hope this helps others
out there on this error as there was little around on the web. This
problem crashed the app.

Cheers

Nov 16 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
5021
by: 6tc1 | last post by:
Hi all, I have just finished debugging a windows application and have solved the problem - however, I want to be sure that I understand the problem before I move on. Before I detail the problem, this problem requires some understanding of threading concepts. Basically, the class contained both a PictureBox object as well as a corresponding Image object (they both had a copy of the same picture). The following was used to access the...
0
2180
by: Sam Barham | last post by:
I have a ListView control, for which I have overwritten the WndProc method to gain access to the WM_PAINT message and generate my own OnPaint and OnPaintBackground messages, in order to colour the columns of the listview to my liking. When a row of the listview is selected, some controls are displayed on that row of the listview (so sort of like a property list thingy). In order to get the controls (specifically buttons) to display how I...
1
3234
by: Hadar | last post by:
Hi, I'm getting "object is currently in use elsewhere" when I use System.Drawing.Graphics.MesureString. This is what I do: My controls use a utility class the helps it to mesure strings. To get the best performance for the utility class, its members, as well as the System.Drawing.Graphics object, are static:
1
2405
by: kCura | last post by:
First off, I'm sorry if this isn't the write thread to post this message but I couldn't find one dedicated to System.Drawing. I'm developing an intranet application in VB.NET that uses a Hosted Windows Form (HWF) dedicated to image manipulation. This HWF is also supposed to allow the user to print an image to their default printer. I'm using a System.Drawing.Printing.PrintDocument object to initiate printing, and everything works locally...
4
10362
by: Jos Lavrijsen | last post by:
When i try to re-use brushes or pens over multiple threads, i often get an InvalidOperationException with the message 'object is currently in use elsewhere'. I also tried this by re-using fonts but no problems there. So, it looks like brushes and pens cannot be used in different threads simultaneously. Looks like a dotnet bug to me. This exception is easily reproducible with the following code, both on single
4
5708
by: JJ | last post by:
When I run my form prog, if I maximise, then minimise (i..i. force the GUI to redraw) I get the following error: "The object is currently in use elsewhere" At this line: e.Graphics.DrawString(MenuText.Substring(0, 1), underLinedFont, FontBrush, textLayoutRectangle, sf)
4
7791
by: Mau Kae Horng | last post by:
Hello, I have a C# Windows Forms application for machine. Due to some unknown reasons, the application face problems with unexpected exceptions happening, resulting in two red lines forming a red cross across a certain control (the entire form, labels and so on). I get the following message in MessageBox.
4
2291
by: =?Utf-8?B?Qm9uaQ==?= | last post by:
Hi, I got this problem. I'm implementing a pluggable winform program. My plugins are usercontrol and I load them in my program through a interface. Now if I close my application an error occurs: "Object is currently in use elsewhere". If I comment the line where a I use the Activator.CreateInstance it doesn't happen. I tried to disposed the object created but nothing but If I do a simple new of my object without using reflection it...
0
2328
by: para15000 | last post by:
Hello I have a C# desktop application in which one thread that I create continously gets an image from a source(it's a digital camera actually) and puts it on a panel(panel.Image = img) in the GUI(which must be another thread as it is the code-behind of a control. The application works but on some machines I get the following error at random time
0
9072
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9333
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8328
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6869
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4771
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4942
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3395
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2872
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2284
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.