Hi. I’m using Wisej 3.5.5 and C#, Visual Studio 2022. I defined a custom control that have a Wisej.Web.Timer on it,
That control is created dynamically and added on a tab page, and after that the timer is enabled by code and works as expected. When the tag page is closed, the timer still works. I never explicitly dispose my control, I assumed that closing the parent (tab page) will do.
Please advice.
“created a UserControl (let’s call it UC1) – added a timer on it (via toolbox)”- this is the issue- the timer can’t be added to a specific control. Adding the timer in the designer doesn’t mean that the timer is tied to the UserControl.
Here’s the Timer documentation, you will find this useful: https://docs.wisej.com/api/wisej.web/other-components/wisej.web.timer
I would recommend creating the timer via code when the UserControl is created, ie: Timer timer1 = new Timer();
Dispose of the timer when the UserControl is disposed of. Attach an event handler to the Disposed event of the UserControl (https://docs.wisej.com/api/wisej.web/general/control#disposed). When the event fires, dispose of the timer. The code for this is timer1.Dispose();
(Assuming you used the default name for the timer.)
Your code is wrong in some way. A Timer cannot be a child of any control-so that’s why it’s not being disposed of when your custom control is. Use the designer and add a timer from the toolbox, then check the Designer.cs file to see the correct way to add a container for components. You will need to dispose of the timer explicitly via code.
If this does not fully answer your question, please provide a sample, following the guidelines under “Before Posting an Issue”” https://wisej.com/support/question/forum-guidelines and we will take a look at it.
Please login first to submit.