473,499 Members | 1,974 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Timer/debugger interface problem

I have narrowed down a previous problem to the following more specific
items:

1) I have my startup object in VB.NET (VS 2003) set to Sub Main().

2) Inside of Sub Main() I do a "Application.Run(MyMainForm)"

3) Inside of MyMainForm_Load I create an object, ie: "poMyObj=new clsMyObj"

4) Within poMyObj I create a new System.Threading.Timer instance. I use a
delegate with AddressOf to fire a certain function whenever the timer fires
(the function
is called MyFunction(), and works fine).

5) Everything works like a charm!

6) HOWEVER: Inside the timer callback function (ie: the MyFunction()
function) I place a
breakpoint. When the debugger stops I try to display any labels from
MyMainForm and
just referencing them cause VB.NET to hang. This problem only occurs when
the debugger
trys to reference controls on the form. If I don't use the debugger the
controls can be
referenced by the object's VB code just fine - updating and refreshing data.
Why can't the debugger access the form's controls but everything else can?
Note: when
the problem is occurring I can display any local program variable values,
but I can't
display anything from the form unless I do it without stopping via a
breakpoint.

Any ideas?

Tom
Nov 21 '05 #1
5 1480
What is the interval of the timer? Is it possible the timer is firing
before the form's constructor is finished? Can you delay starting the
timer in your custom object until the last thing in the form;'s
constructor?

Just a thought.

Nov 21 '05 #2
An additional helpful note: If I do nothing but change the startup object to
MyMainForm then everything works perfectly, including debugger references to
the form's controls. If I then change back to Sub Main() as a startup
object, the problem comes back.

Tom

"Tom Edelbrok" <an*******@anonymous.com> wrote in message
news:v0Pge.37731$0X6.25714@edtnps90...
I have narrowed down a previous problem to the following more specific
items:

1) I have my startup object in VB.NET (VS 2003) set to Sub Main().

2) Inside of Sub Main() I do a "Application.Run(MyMainForm)"

3) Inside of MyMainForm_Load I create an object, ie: "poMyObj=new
clsMyObj"

4) Within poMyObj I create a new System.Threading.Timer instance. I use a
delegate with AddressOf to fire a certain function whenever the timer
fires (the function
is called MyFunction(), and works fine).

5) Everything works like a charm!

6) HOWEVER: Inside the timer callback function (ie: the MyFunction()
function) I place a
breakpoint. When the debugger stops I try to display any labels from
MyMainForm and
just referencing them cause VB.NET to hang. This problem only occurs when
the debugger
trys to reference controls on the form. If I don't use the debugger the
controls can be
referenced by the object's VB code just fine - updating and refreshing
data.
Why can't the debugger access the form's controls but everything else can?
Note: when
the problem is occurring I can display any local program variable values,
but I can't
display anything from the form unless I do it without stopping via a
breakpoint.

Any ideas?

Tom

Nov 21 '05 #3
Very good idea but no luck ... I set the timer to make its first firing of
the callback after 5 relative seconds (ie: the "due" time). The timer fires
in exactly 5 seconds (ie: this will be 5 seconds after the constructor
completes, because the state timer is created in the constructor). But the
same problem happens.

Thanks for the idea.

Tom

"Chris Dunaway" <du******@gmail.com> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...
What is the interval of the timer? Is it possible the timer is firing
before the form's constructor is finished? Can you delay starting the
timer in your custom object until the last thing in the form;'s
constructor?

Just a thought.

Nov 21 '05 #4
One more piece of information:

When I set the form as the startup object, and the form_load creates my
application object, I display application.messageloop and find it to be TRUE
(ie: when my form timer fires).

But whenever I try the other situations described (ie: I create a state
timer within my application object, and set Sub Main() as the startup
object) I find that application.messageloop is always FALSE. This coincides
with the debugger not being able to access controls on the form.

Tom

"Chris Dunaway" <du******@gmail.com> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...
What is the interval of the timer? Is it possible the timer is firing
before the form's constructor is finished? Can you delay starting the
timer in your custom object until the last thing in the form;'s
constructor?

Just a thought.

Nov 21 '05 #5
I think I have it figured out:

Because I've been using a System.Threading.Timer it goes out and grabs a
free thread (I think), and the free thread grabbed has no message pump
running against it, therefore when in the debugger I can't access the
controls on the form.

But if I create a System.Windows.Forms.Timer instead, it all seems to work
fine - I can access my form controls from the debugger, and the timer
performs its tick functions perfectly. I'm guessing that because the
Systems.Windows.Forms.Timer is required to have a message pump and is
optimized for use with forms that it binds itself to the message pump of
your default application form's thread, and therefore has a message pump to
use.

Works great regardless of what's happening under the hood!

Tom


"Chris Dunaway" <du******@gmail.com> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...
What is the interval of the timer? Is it possible the timer is firing
before the form's constructor is finished? Can you delay starting the
timer in your custom object until the last thing in the form;'s
constructor?

Just a thought.

Nov 21 '05 #6

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

Similar topics

3
2943
by: Lloyd Sheen | last post by:
I have a problem where I cannot read (all the time) a file when caught by the FileSystemWatcher. What I have done to get past this is create an array of events (when I receive one I add it to the...
2
2536
by: Sam Miller | last post by:
Normally the debugger (visual studio .net environment) is good at pointing out the line of code that caused an exception.... except when that code is executed as part of a timer handler. In the...
3
9499
by: Scott H | last post by:
Hello, I'm having a go at writing my first Windows Service in VB.NET and I'm having a problem. I have it installed ok and started the service sucessfully, I can stop it, and restart it fine, the...
4
5333
by: Ben | last post by:
Hello everybody I got confused by this problem for which I don't have a logical explanation. There is a Thread (ThreadA) which receives Events from another system thread (ThreadS). ThreadA then...
5
12168
by: Tony Gravagno | last post by:
I have a class that instantiates two Timer objects that fire at different intervals. My class can be instantiated within a Windows Form or from a Windows Service. Actions performed by one of the...
4
2799
by: Bails | last post by:
Hi Im an absolute beginner in programming and am using VB.Net Express. To start my larning I decided to do a "Real World" app instead of "hello world" and am creating a Poker Countdown clock. ...
3
3817
by: Beemer Biker | last post by:
Unaccountably, I cannot re-enable a timer from an background thread. The disable works fine, I just cannot get it to start back up. There is no method "InvokeRequired" like there is for...
19
5169
by: colin | last post by:
Hi, Im trying to time some parts of my code using the Stopwatch class, but it is so slow, I tried the QueryPerformanceFrequency() but this seems to be just as slow, if I just simply call this...
12
4458
by: Zytan | last post by:
I have a Timer class set to trigger every second. The Tick function that is called every second uses a lock to prevent multiple ticks from executing the same code at the same time. The code...
0
7131
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,...
0
7007
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...
1
6894
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...
0
5470
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,...
0
4600
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...
0
3099
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...
0
3091
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
665
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
297
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...

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.