I'm having a problem that occurs at random in my app.
I get an exception
"Cannot Access a disposed object"
In MSCorLib when calling boolean Change (int32, int32)
Stack trace reveals
System.Threadin g.Timer.Change( Int32, int32)
at Systems.Timers. UpdateTimer()
at System.Timers.T imer.set_Interv al(double value)
and so on thru my app.......
The problem occurs when i set the interval on the timer.
Sometimes this occurs within 4 minutes of starting the app....
The record today is 22 hours........
Theres nothing in my code to dispose of the timers
they should just sit there....
any ideas?! :-s
Cheers 5 8508
theinvisibleGho st wrote: I'm having a problem that occurs at random in my app. I get an exception "Cannot Access a disposed object" In MSCorLib when calling boolean Change (int32, int32)
Stack trace reveals System.Threadin g.Timer.Change( Int32, int32) at Systems.Timers. UpdateTimer() at System.Timers.T imer.set_Interv al(double value)
and so on thru my app.......
The problem occurs when i set the interval on the timer. Sometimes this occurs within 4 minutes of starting the app.... The record today is 22 hours........
Theres nothing in my code to dispose of the timers they should just sit there.... any ideas?! :-s
Cheers
Apart from calling Dispose "by hand" (=hardcoded), an object could (will)
get disposed if all references to it go out of scope. Could that be the case
here?
You might show some more details of your app: where do you create
that timer? Where do you use it? Is it a win-form or web-form app?
etc.
Hans Kesting
Thanks for your reply.
The app is windows based.
I'm having this occur in more than once class, although it's occured
most in a class
I call LEDControl (Simulates an LED!). The LED has a flash timer (to
make it flash!)
The timer is created as a private attribute on creation of the LED
object.
No dispose methods are called within the class except on disposal of
the LED object.
The LED itself is definitley not disposed of (I can see it for a
start)....
The timer is never set to null or infact set to anything after the
line
private System.Timers.T imer flashTimer = new System.Timers.T imer();
so as far as I can see it should always have one and only onereference
to it, until
the LED is disposed off (When the application ends).
I tried placing a MessageBox in the Dispose event of the LED, and it
never showed,
so the timer cannot have been disposed of there.....
"Hans Kesting" <ne***********@ spamgourmet.com > wrote in message
news:uV******** ******@TK2MSFTN GP10.phx.gbl... an object could (will) get disposed if all references to it go out of scope.
This is not true.
- Michael S
Any more ideas anyone?
Cheers
theinvisibleGho st wrote: Thanks for your reply. The app is windows based. I'm having this occur in more than once class, although it's occured most in a class I call LEDControl (Simulates an LED!). The LED has a flash timer (to make it flash!) The timer is created as a private attribute on creation of the LED object. No dispose methods are called within the class except on disposal of the LED object. The LED itself is definitley not disposed of (I can see it for a start).... The timer is never set to null or infact set to anything after the line
private System.Timers.T imer flashTimer = new System.Timers.T imer();
so as far as I can see it should always have one and only onereference to it, until the LED is disposed off (When the application ends).
I tried placing a MessageBox in the Dispose event of the LED, and it never showed, so the timer cannot have been disposed of there.....
theinvisibleGho st wrote: Any more ideas anyone? Cheers
theinvisibleGho st wrote: Thanks for your reply. The app is windows based. I'm having this occur in more than once class, although it's occured most in a class I call LEDControl (Simulates an LED!). The LED has a flash timer (to make it flash!) The timer is created as a private attribute on creation of the LED object. No dispose methods are called within the class except on disposal of the LED object. The LED itself is definitley not disposed of (I can see it for a start).... The timer is never set to null or infact set to anything after the line
private System.Timers.T imer flashTimer = new System.Timers.T imer();
so as far as I can see it should always have one and only onereference to it, until the LED is disposed off (When the application ends).
I tried placing a MessageBox in the Dispose event of the LED, and it never showed, so the timer cannot have been disposed of there.....
Found the problem, eventually!
It is a known bug if you search hard enough across the Net.
I found a link http://www.kbalertz.com/kb_842793.aspx
Basically as soon as you stop a timer, the internal
System.Threadin g.Timer becomes available for Garbage Collection,
sometimes causing the elapsed event not to occur, or sometimes
causing a disposed reference exception.
Although not described in the article, my soloution was
to create a new timer every time the timer was to be
stopped and re-add the elapsed events. Not efficient but easy,
and not a problem processor wise with me.
This has totally solved my problem.
Cheers for all who responded.
T. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Ryan Park |
last post by:
Hi,
//SITUATION
I got a panel control that hold a certain position on a form.
Every controls or UIs are on this panel.
At certain situation, I called dispose() method of this panel control
and change it with other panel which contains other business logic and
UI controls.
|
by: D Witherspoon |
last post by:
I use the following code to open up a form.
-------------------------------------------------------
If fImage Is Nothing Then
fImage = New frmImage
End If
fImage.Show()
|
by: Asaf |
last post by:
Hi,
When I am doing a POST to a SSL URL I am getting this error on first attempt
"Cannot access a disposed object named "System.Net.TlsStream"."
After the first attempt all works fine, here is the Stack Trace
at System.Net.TlsStream.InnerWrite(Boolean async, Byte buffer, Int32
offset, Int32 size, AsyncCallback asyncCallback, Object...
|
by: Shawn |
last post by:
Hi.
In my application I store information about the user in the session object.
Since I'm storing sensitive information I encrypt it before storing and
decrypt it when I need to use it again. The encryption object I use is
stored in the Application object. My problem is that after a while the
encryption object becomes unusable. When I...
|
by: Tracey |
last post by:
sorry I post this problem again. I have to stop my work
to fix the problem.
I'm doing a multi form application(Not a MDI one).
My startup form say Form1 has a datagrid say datagrid1,
when I click a grid item in datagrid1, I wanna show
form2. In my code, I achieved that with:
Public class Form1
Inherits System.Windows.Forms.Form
| |
by: Bernie Yaeger |
last post by:
I'm launching one window from another. I have a close button in the first
window and when I click it, it executes me.close. However, the form also
has a treeview control. If I launch the second window on a treeview node
selection, the second window launches just fine; however, if I have me.close
in the code right after it, I get the error...
|
by: ed |
last post by:
Hi,
Here's my code
'in form
WithEvents formReplace As New Form
Private Sub cmdFind_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdFind.Clic
formReplace.Show(
|
by: Amit Dedhia |
last post by:
Hi
I am having problem working with Timers in C++/CLI (the .NET version
of C++)
I have an application which has several forms with pictureBox controls
on it. There is a background timer executing every 250ms and it
generates a display image (using some real time data) and pastes those
on the picture box. As the picturebox was generated...
|
by: sdanda |
last post by:
Hai i am working on vb.net.
In my application I created four forms.Those are first.vb,f1.vb,f2.vb and f3.vb
In firstvb I added 3 checkboxes and a "display" button.The 3 checkboxes are used to display the forms f1,f2 and f3.If first checkbox is checked then it displays the f1 form.Similarly for f2 and f3 also.I kept all this code in the display...
|
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...
|
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...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
|
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...
|
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...
|
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...
|
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...
|
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.
| |