473,776 Members | 1,665 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

InvalidOperatio nException: The object is currently in use elsewher

I have a DataGrid control on a Form. The data of the control is added by
another application by Remoting.
It means that a worker thread is invoking a UI thread. Therefore I used a
delegate in the Form invocation like this:
public delegate void AddDefectEventH andler(string xmlDefect);

public void AddDefect(strin g xmlDefect)
{
this.Invoke(new AddDefectEventH andler(this.Add DefectUI), new object []
{xmlDefect});
}

private void AddDefectUI(str ing xmlDefect)
{
// Doing the DataGrid data adding
}

I don't know if it's a thread problem, but sometimes I get the following
exception:

"System.Invalid OperationExcept ion: The object is currently in use elsewhere.
at System.Drawing. Graphics.Dispos e(Boolean disposing)
at System.Drawing. Graphics.Dispos e()
at System.Windows. Forms.PaintEven tArgs.Dispose(B oolean disposing)
at System.Windows. Forms.Control.W mPaint(Message& m)
at System.Windows. Forms.Control.W ndProc(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.Callback(In tPtr hWnd, Int32 msg,
IntPtr wparam, IntPtr lparam)"
Can anybody tell me what wrong?
----------
Thanks
Sharon
Jan 4 '06 #1
8 3561
Hi Sharon,

Welcome to MSDN newsgroup!

Based on my understanding and the error message, the current problem is
caused when the Graphics object is being used by other handles it calls
the Dispose method.

At the current stage, please check whether you use the object in other
parts of your project. Additionally, I recommend you make a simple demo
which can repro the current problem and send it to me. It¡¯ll help me to
narrow down the current problem. Thanks for your understanding! My alias is
v-****@online.mic rosoft.com (remove .online).

I¡¯m looking forward your reply!

Regards,

Yuan Ren [MSFT]
Microsoft Online Support

Jan 5 '06 #2
I can send you the code I'm using, but to summarize will take some time.

The info I have right now is that I'm not using multithreading that uses the
DataGrid control.
I'm not using GDI+ of the DataGrid control at all.

After taking a closer look at the exception, you can see that the invocation
was initiated by the Windows OS (NativeWindow.C allback). So maybe it open a
new thread that access the control graphics outside the UI thread.

To prevent that, I override the OnPaint() of the DataGrid and locked with
the lock statement.
Furthermore; at this OnPiant() I'm checking if the calling thread is the UI
thread or other, so it is other thread then the UI thread I'll know I I'll
post in here.

Any other idea is more then welcome.
--------
Thanks
Sharon
Jan 10 '06 #3
Hi Sharon,

Thanks for your feedback.

First, this is not caused by Windows OS code, but .Net winform FCL code.
(NativeWindow.C allback). Based on the call stack, the exception is caused
by .Net Winform code when it is processing WM_PAINT message for the form.

I am not sure if your finding of override the OnPaint of DataGrid is the
root cause. Does it resolve your problem?

Currently, I can find a known bug regarding this call stack. Based on the
bug details, it seems that it is caused by ATI Rage Pro driver, and
updating the driver fixes the problem. You may give this a try.

If you still can not workaround this problem, I think a reproduce little
sample is helpful for us to understand this issue. Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Jan 11 '06 #4
Hi Jeffrey,

Thanks for your reply.

I don't really understand what driver you want me to install (the ATI Rage
Pro driver). Is it the graphics board device driver? it sound like it should
be something higher then that.

Actually, I have this problem in tree of our control:
(1) Native .NET GroupBox control.
(2) DataGrid that is inside my own UserControl.
(3) My own MAP control derived from the UserControl.

*The first one we don't care about because its form windows is hidden.
*The second one did not occur yet since I locked the OnPaint() by deriving
the DataGrid and locking the call to the bas.OnPaint().
* The third is still happening, although I locked its OnPaint(), but it's
because I'm using the GDI+ in some more places of the MAP control code other
then its OnPaint().

In order to confirm my suspicion that the .Net winform FCL code
(NativeWindow.C allback) is calling from a NON UI thread, I warped the
Application.Run (new MyForm()) in a try-catch, and also added handling for
unhandled exceptions
(System.Threadi ng.Thread.GetDo main().Unhandle dException). in both the catch
exception I'm shown a MessageBox with the error. (This two handlers are at
the main form context).
Now the spoken exception was thrown again yesterday (Only in my MAP control)
BUT the two exception handling popped their MessageBoxes with the same
exception type and description AT THE SAME TIME (almost).

Therefore I'm quite sure that two threads was trying to use the GDI+ of the
control and one of them is not the UI thread. And as I mentioned before; I'm
not using any multi threading on the UI.
So my conclusion is that the .Net winform FCL code (NativeWindow.C allback)
do have a bug because it's invoking a UI call within a non UI thread.
Now I can prevent this error by locking all the code that uses any GDI+.

Maybe you have a better ideas?
---------
Thanks
Sharon
Jan 11 '06 #5
Just to make sure:

Do I need to do Graphics.Dispos e() / Image.Dispose() /
Graphics.Releas eHdc(pDC) or should I let the garbage collector (GC) to do
that for me ?

Currently I'm disposing all the graphics objects that I'm using manually
(invoking the Dispose myself or using the using statement).
--------
Thanks
Sharon
Jan 11 '06 #6
Some bad news...

The error was reproduce in our QA at the DataGrid itself although its
OnPaint() is protected by a lock.
Furthermore, the thrown exception was not caught nor by my try-catch around
the application Main function, nor by the unhandled exception catcher. It was
caught again by the CLR.

*** Important note: The QA PC has a dual Xeon dual core CPU, and this error
is only reproduced in that PC. But of course the QA PC does much more testing
then our development PC's.
Do you think it has anything to do with the dual CPU?

Does the .Net winform FCL code (NativeWindow.C allback) invoke the control
code from another thread?
--------
Thanks
Sharon
Jan 12 '06 #7
More news:
I thinks it's a bad new because it tells me that I can not bypass the
problem at hand.

I disabled 3 CPU's so only single CPU will execute my program (I did it
using the Windows Task Manager), Yes, after only a few hours it still
happened. Same exception!

Note: The QA PC does not have dual CPU dual core as I said before. It has
dual XEON CPU's with hyperthreading. And it's shown on the Task Manager as 4
CPU's.
Anyone can help here please ?
-------
Thanks
Sharon
Jan 15 '06 #8
Hi Sharon,

Sorry for late response!

At the current stage, this issue would be a product problem, if you need a
solution to work around this problem, it is better for you if one of our
PSS support engineers could work with you. This may need you submit a
support incident in Microsoft PSS (Product Support Service). As a MSDN
subscriber, you have two free support incidents.

By the way, if the problem is confirmed by Microsoft PSS as a product
issue, PSS won't charge money. Every MSDN subscriber has two free support
incidents. You could use one of them to contact Microsoft PSS. So you don't
need to pay money yet. Surely if the issue is a product issue, you still
have two free support incidents.

For your reference, I attached steps to contact Microsoft PSS here: You can
contact Microsoft Product Support directly to discuss additional support
options you may have available, by contacting us at 1-(800)936-5800 or by
choosing one of the options listed at

http://support.microsoft.com/common/...gp;en-us;offer
prophone

Regards,

Yuan Ren [MSFT]

Microsoft Online Support

Jan 17 '06 #9

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

Similar topics

2
4099
by: Mike Fiedler | last post by:
On a client web services request, I have a SoapExtension that is adding a header to the message in the BeforeSerialize stage. If the Web Service request is for an operation with style="document"/use="literal", everything works fine - the header is added, message is serialized and all is ok. If the Web Service request is for an operation with style="rpc"/use="encoded":
4
10366
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
0
1908
by: banduraj | last post by:
I get an System.InvalidOperationException when trying to Serialize a struct that has a type refrenced from another library. The exception is: System.InvalidOperationException was unhandled Message="Unable to generate a temporary class (result=1).\r\nerror CS0012: The type 'SecureSpeak.Protocol.ssContactItem' is defined in an assembly that is not referenced. You must add a reference to assembly 'SecureSpeak.Protocol, Version=1.0.0.0,...
2
12625
by: snowie | last post by:
I have a simillar problem to what others have had before me. I just can't find the solution in any earlier post here at the scripts (or any other forum). I am calling a web service that returns a string, the string is an object serialized into XML. The XML returned could look like: ...
1
2154
by: chad | last post by:
system.InvalidOperationException: the object is currently in use elsewhere... has anyone experienced this error before? I am occasionally getting this error. I can't figure out what could possibly cause it. When the prog runs thru the loop, the error could be thrown anytime. Sometimes it doesn't at all. Seems like it's telling me that the picturebox is in use at the same time that it wants to be updated. But I timed it... displayImg =...
3
14225
by: Joseph Geretz | last post by:
System.InvalidOperationException: WebServiceBindingAttribute is required on proxy classes. My environment: Visual Studio 2005, targeting FX 2.0; I've developed a Web Service which uses DIME to transfer file attachments to and from the server. I'm using WSE 2.0 SP3 which is supposed to support FX 2.0, as far as I know. (We will soon move on to MTOM, however I'm stuck with DIME for now; the solution was originally written for FX 1.1, and I...
2
3861
by: Spam Catcher | last post by:
Anyone know what this error means? The Undo operation encountered a context that is different from what was applied in the corresponding Set operation. The possible cause is that a context was Set on the thread and not reverted(undone). It seems to pop up when I use nSoftware's IPDaemon...
2
4311
by: Jeroen | last post by:
We are experiencing a tuff-to-debug problem ever since we introduced a WebBrowser control into our failry large application. I'm not sure if the problem description below contains enough details, so if I need to elaborate on something please ask for it. We have a UserControl with a WebBrowser on it. This UserControl is instantiated a few times during the program run, depending on user interaction. The WebBrowser then navigates to a local...
0
2329
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
9628
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
9464
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10122
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10061
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9923
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...
1
7471
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
6722
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5368
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...
3
2860
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.