Hello,
I had an earlier post regarding a strange exception I
(thought) I was getting in my windows form. I have since
been able to trace the problem to a picturebox control on
my form. I can reproduce the exception consistently, but
it seems to be timing dependent. Here is what happens:
I have a subform that I open, load an image from a file
into my PictureBox, take some user input, then I hide the
form. The last thing I do before I Hide the form is
release the Image's hold on the file by using Dispose().
This is where the problem occurs. The code is as follows:
'Release image resource
Try
PictureBox1.Ima ge.Dispose()
Catch tobj As Exception
MsgBox(tobj.Mes sage)
End Try
Try
Application.DoE vents()
Catch e
MsgBox(e.Messag e)
End Try
Me.Hide()
The exception is caught in the second Try. The message
says:
System.Argument Exception occured in
System.Windows. Forms.dll
Additional Information: Invalid Parameter Used.
Inspection of the exception shows that it is thrown by
System.Drawing. Inspection of the Stack Trace shows that
it is thrown from the "get_Width" method within the dll.
It appears to stem from when the PictureBox is redrawing
itself.
So here is my theory: It seems that there is some sort
of race condition between when I call Image.Dispose() and
when the Image is repainting itself that is causing this
problem. I haven't yet been able to verify this. Any
ideas? I would appreciate any help or input on this
problem.
Thanks alot. I have included the Stack Trace below.
Tyler Foreman
StackTrace" at System.Drawing. Image.get_Width ()
at System.Drawing. Image.get_Size( )
at System.Windows. Forms.PictureBo x.get_ImageRect angle()
at System.Windows. Forms.PictureBo x.OnPaint
(PaintEventArgs pe)
at System.Windows. Forms.Control.P aintWithErrorHa ndling
(PaintEventArgs e, Int16 layer, Boolean disposeEventArg s)
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.DebuggableC allback
(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at
System.Windows. Forms.UnsafeNat iveMethods.Disp atchMessageW
(MSG& msg)
at
System.Windows. Forms.Component Manager.System. Windows.Forms
..UnsafeNativeM ethods+IMsoComp onentManager.FP ushMessageLoop
(Int32 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.DoEvents()
at MYAPP.Form2.Sav eEvent_Click(Ob ject eventSender,
EventArgs eventArgs) 2 5961
Hi Tyl;er,
PictureBox1.Ima ge.Dispose() will dispose of the underlying resource used
by the Image, ie the internal BitMap. PictureBox1.Ima ge is still there,
however, so when PictureBox1_Pai nt occurs, it says "Ah here's an Image to
draw" but then there's no BitMap inside. :-(
You need:
PictureBox1.Ima ge.Dispose()
PictureBox1.Ima ge = Nothing
Then System.Windows. Forms.PictureBo x.OnPaint won't bother trying to call
get_ImageRectan gle().
Regards,
Fergus
Thanks Fergus! That did the trick!
Cheers,
Tyler Foreman -----Original Message----- Hi Tyl;er,
PictureBox1.Ima ge.Dispose() will dispose of the
underlying resource usedby the Image, ie the internal BitMap. PictureBox1.Ima ge
is still there,however, so when PictureBox1_Pai nt occurs, it says "Ah
here's an Image todraw" but then there's no BitMap inside. :-(
You need: PictureBox1.Ima ge.Dispose() PictureBox1.Ima ge = Nothing
Then System.Windows. Forms.PictureBo x.OnPaint won't
bother trying to callget_ImageRecta ngle().
Regards, Fergus
. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Craig Vermeer |
last post by:
Hi All,
I noticed an interesting issue the other day, and thought someone here
might be able to shed some light on things.
I have a situation where I'm using asynchronous delegates, and an
exception is getting thrown from within the AsyncCallback on the
delegate. For some reason, this causes the AsyncCallback delegate to be
executed twice. Now, I understand how to stop the situation from
happening. However, what I didn't know was...
|
by: PB |
last post by:
As part of an ASP.NET WEb Application I have a routine (relevant portion is
below) that lets users rotate a photo (jpg or gif).
The routine works just fine if it is run once. If run a second time
immediately after the first, then an exception with the following message is
thrown:
"The process cannot access the file
"C:\InetPub\Files\MyApp\SubDir\MyPic.JPG" because it is being used by
another process"
|
by: Minh |
last post by:
I create a C# Project using Windows Application template,
I add an imagelist to Form, and add icon to imagelist1.
After that, I run Project, but an Exception has occured. I can fix it even
reinstall Visual Studio .NET 2003
this is the Code auto-generated by VSS:
_____________________________
|
by: will |
last post by:
Hi all. I've got an question about how to catch an exception.
In Page_Load, I place a DataGrid, dg1, into edit mode. This will
call the method called GenericGridEvent. GenericGridEvent will
call a mehtod called ExceptionGenerator that will generate a run-time exception.
The exception is caught in GenericGridEvent, but it isn't caught in
InitializeComponenet (which doens't suprise me). I can't figure
out where to catch an error that may...
|
by: Brian Henry |
last post by:
I get the following exception only on one system (dev system) and not on any
others... what could cause this?! I can access the SMTP server just fine in
E-Mail applications on the machine...
See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.
************** Exception Text **************
System.Web.HttpException: Could not access 'CDO.Message' object. --->
| |
by: ZorpiedoMan |
last post by:
Well, I'm still wondering around in the "land of the lost exception"...
It seems that controls that are bound to a class and the class throws an
error in the SET method of the bound member, the exception cannot be
caught. I have wrapped my entire application in all the global
exception handlers I can find, and still to no avail. In fact all the
Try/Catches and Exception event handlers are worthless...
Put on your advanced thinking...
|
by: Chuck Cobb |
last post by:
I'm implementing a centralized exception handling routine using the
Enterprise Library Exception Management Application Block.
I trap all unhandled exceptions to one place using the following method:
// --- Create an Exception Handler for Thread Exceptions ----------------
Application.ThreadException += new
ThreadExceptionEventHandler(OnThreadException);
|
by: Eugene |
last post by:
Hi, I have a problem when loading one of my dll. I have a main class that
would load a winform in another dll using reflection. When I load it using
Assembly.CreateInstance(DLLName.DLLFormName), an exception is thrown with the
message: "Exception has been thrown by the target of an invocation."
?ex.Source
"mscorlib"
?ex.GetType.AssemblyQualifiedName
"System.Reflection.TargetInvocationException, mscorlib, Version=1.0.5000.0,
|
by: neoupadhyay |
last post by:
External component has thrown an exception.
C:\Program Files\Microsoft Visual Studio 8\Common7\IDE> "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\csc.exe" /t:library /utf8output /R:"C:\WINDOWS\assembly\GAC_MSIL\System.Web.Extensions\1.0.61025.0__31bf3856ad364e35\System.Web.Extensions.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.Configuration\2.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll"...
|
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,...
|
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,...
| |
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |