By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,117 Members | 2,142 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,117 IT Pros & Developers. It's quick & easy.

forms timers, events, and threading

P: n/a
Bob
My WinForms app runs on the single default thread, and uses a single
SqlConnection object for all queries. I need to use one or more timers to
periodically execute some of them. My own testing indicates that the forms
timer does not operate on its own thread and will not cause a query to be
sent to use the single SqlConnection while another is being executed from
the handling of other events. Is that right? I just want to be 100% sure
before I commit to this design.

Bob
Nov 21 '05 #1
Share this Question
Share on Google+
13 Replies


P: n/a
Bob,

I am not completly sure of your question, however a thread does only one
operation per operation. So when there is a longtime taking SQL operation
by instance a dataadapter update, than that will first be done, before the
timer event is catched.

I hope this helps?

Cor

"Bob" <no***@nowhere.com>
...
My WinForms app runs on the single default thread, and uses a single
SqlConnection object for all queries. I need to use one or more timers to
periodically execute some of them. My own testing indicates that the forms
timer does not operate on its own thread and will not cause a query to be
sent to use the single SqlConnection while another is being executed from
the handling of other events. Is that right? I just want to be 100% sure
before I commit to this design.

Bob

Nov 21 '05 #2

P: n/a
Bob,

However before I forget it, why do you not test this kind of questions
yourself when it is so important. A small test program is in my opinon fast
enough made?

sub Myprocedure Y
threading.thread.sleep(4000)
end sub

sub Timer
test if it is throw by setting the timertick to 1000 miliseconds
end sub

Cor

"Bob" <no***@nowhere.com>
...
My WinForms app runs on the single default thread, and uses a single
SqlConnection object for all queries. I need to use one or more timers to
periodically execute some of them. My own testing indicates that the forms
timer does not operate on its own thread and will not cause a query to be
sent to use the single SqlConnection while another is being executed from
the handling of other events. Is that right? I just want to be 100% sure
before I commit to this design.

Bob

Nov 21 '05 #3

P: n/a
Bob
You obviously missed the "my own testing" part of my message.

Bob

"Cor Ligthert" <no************@planet.nl> wrote in message
news:OM**************@TK2MSFTNGP09.phx.gbl...
Bob,

However before I forget it, why do you not test this kind of questions
yourself when it is so important. A small test program is in my opinon fast enough made?

sub Myprocedure Y
threading.thread.sleep(4000)
end sub

sub Timer
test if it is throw by setting the timertick to 1000 miliseconds
end sub

Cor

Nov 21 '05 #4

P: n/a
Bob
I was wrong. 100% sure just wen to 0%.

OK, new question. How can I get message boxes and other modal dialogues to
stop timer tick events just like the interventing execution of other
event-driven code code?

I guess I'll have no choice now but to brew my own message boxes. What a
pain.

Bob

"Bob" <no***@nowhere.com> wrote in message
news:OC**************@TK2MSFTNGP11.phx.gbl...
My WinForms app runs on the single default thread, and uses a single
SqlConnection object for all queries. I need to use one or more timers to
periodically execute some of them. My own testing indicates that the forms
timer does not operate on its own thread and will not cause a query to be
sent to use the single SqlConnection while another is being executed from
the handling of other events. Is that right? I just want to be 100% sure
before I commit to this design.

Bob

Nov 21 '05 #5

P: n/a
Bob,

For which timer do you want to know this?

Windows.forms.timer
or
System.timers.timer
or
System.threading.timer
or
Another one

Cor
I was wrong. 100% sure just wen to 0%.

OK, new question. How can I get message boxes and other modal dialogues to
stop timer tick events just like the interventing execution of other
event-driven code code?

I guess I'll have no choice now but to brew my own message boxes. What a
pain.

Bob

Nov 21 '05 #6

P: n/a
No, 100% sure of having right switched to 100% sure of having wrong. The
100% sureness is there all the time <LOL>

Can't you just before showing the message set the timer.enabled = false and
reset it after showing the messagebox?
I do that, but I'm using system.timer....
Maybe you should switch

HTH
/Kejpa
"Bob" <no***@nowhere.com> wrote in message
news:uy*************@TK2MSFTNGP14.phx.gbl...
I was wrong. 100% sure just wen to 0%.

OK, new question. How can I get message boxes and other modal dialogues to
stop timer tick events just like the interventing execution of other
event-driven code code?

I guess I'll have no choice now but to brew my own message boxes. What a
pain.

Bob

"Bob" <no***@nowhere.com> wrote in message
news:OC**************@TK2MSFTNGP11.phx.gbl...
My WinForms app runs on the single default thread, and uses a single
SqlConnection object for all queries. I need to use one or more timers to periodically execute some of them. My own testing indicates that the forms timer does not operate on its own thread and will not cause a query to be sent to use the single SqlConnection while another is being executed from the handling of other events. Is that right? I just want to be 100% sure
before I commit to this design.

Bob


Nov 21 '05 #7

P: n/a
Bob
Cor and Kejpa,

I really don't care what kind of timers I'm using, the only thing I'm after
is that they don't tick while code is executing doing other events.
Unfortunately I'm willing to bet none of them stop when a message box is
popped up. That's what I'd like, but I'm probably just going to have to
subclass all my timers, then make a custom message box class, and have the
two classes communicate with static methods. I want to avoid adding this
level of complexity if I can help it, but I'm not sure there's any other
way.

Bob
Nov 21 '05 #8

P: n/a
Bob,

Complexity starts mostly that people do not know what they want to archieve
when they can tell that in a simple way, than mostly it is easy to get an
easy procedure as well. As far as I hear you, it seems an easy problem to
solve.

Cor

"Bob" <no***@nowhere.com>

....
Cor and Kejpa,

I really don't care what kind of timers I'm using, the only thing I'm
after
is that they don't tick while code is executing doing other events.
Unfortunately I'm willing to bet none of them stop when a message box is
popped up. That's what I'd like, but I'm probably just going to have to
subclass all my timers, then make a custom message box class, and have the
two classes communicate with static methods. I want to avoid adding this
level of complexity if I can help it, but I'm not sure there's any other
way.

Bob

Nov 21 '05 #9

P: n/a
Bob,
Didn't you ask this question on Sept 29th 2004?

http://groups.google.com/groups?hl=e...TNGP11.phx.gbl

I'm not sure if these threads will help you or not:

http://groups.google.com/groups?hl=e...eb%25404ax.com

http://groups.google.com/groups?hl=e...TNGP12.phx.gbl
Rather then brew your own message box, I would have a well known object (a
Singleton, either the MainForm or my ApplicationContext singleton) have a
pair of methods that "locked" out the Timer events. Alternatively I would
code the Timer events so they were not reentrant (by checking a Static
variable in the method, the third link above has a sample).

Normally I simply code my Timer events so they are not reentrant.

Hope this helps
Jay

"Bob" <no***@nowhere.com> wrote in message
news:uy*************@TK2MSFTNGP14.phx.gbl...
I was wrong. 100% sure just wen to 0%.

OK, new question. How can I get message boxes and other modal dialogues to
stop timer tick events just like the interventing execution of other
event-driven code code?

I guess I'll have no choice now but to brew my own message boxes. What a
pain.

Bob

"Bob" <no***@nowhere.com> wrote in message
news:OC**************@TK2MSFTNGP11.phx.gbl...
My WinForms app runs on the single default thread, and uses a single
SqlConnection object for all queries. I need to use one or more timers to
periodically execute some of them. My own testing indicates that the
forms
timer does not operate on its own thread and will not cause a query to be
sent to use the single SqlConnection while another is being executed from
the handling of other events. Is that right? I just want to be 100% sure
before I commit to this design.

Bob


Nov 21 '05 #10

P: n/a
Bob,

Maybe can this sample that I made for you clear it better.

\\\Needs one button on a form
Private start As Integer
Private WithEvents mytimer As New Windows.Forms.Timer
Private Sub Button1_Click(ByVal sender _
As Object, ByVal e As System.EventArgs) _
Handles Button1.Click
mytimer.Enabled = True
mytimer.Interval = 2000
start = Environment.TickCount
Threading.Thread.Sleep(1000)
Threading.Thread.Sleep(1000)
Threading.Thread.Sleep(1000)
Threading.Thread.Sleep(1000)
End Sub

Private Sub mytimer_Tick(ByVal sender As Object, ByVal _
e As System.EventArgs) Handles mytimer.Tick
mytimer.Enabled = False
MessageBox.Show((Environment.TickCount - _
start).ToString)
End Sub
///
"Bob" <no***@nowhere.com>
Cor and Kejpa,

I really don't care what kind of timers I'm using, the only thing I'm
after
is that they don't tick while code is executing doing other events.
Unfortunately I'm willing to bet none of them stop when a message box is
popped up. That's what I'd like, but I'm probably just going to have to
subclass all my timers, then make a custom message box class, and have the
two classes communicate with static methods. I want to avoid adding this
level of complexity if I can help it, but I'm not sure there's any other
way.

Bob

Nov 21 '05 #11

P: n/a
Bob,

Because that Jay showed us that previous thread, I think that I could make a
better sample.

\\\
Private WithEvents mytimer As New Windows.Forms.Timer
Private Sub Form4_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
mytimer.Enabled = True
mytimer.Interval = 5000
End Sub
Private Sub mytimer_Tick(ByVal sender As Object, ByVal _
e As System.EventArgs) Handles mytimer.Tick
Dim start As Integer
mytimer.Enabled = False
start = Environment.TickCount
MessageBox.Show((Now.ToString("mm-ss")))
mytimer.Interval = 5000 - _
(Environment.TickCount - start)
mytimer.Enabled = True
start = Environment.TickCount
End Sub
///
You have to click inside the 5 seconds for this button, and ending the
program can give an error however it is just to show you this.

This accoording what I now understand from your problem. Know that you never
can use in Net1.1 one ADONET connection more than one time.

I hope this helps?

Cor

"Bob" <no***@nowhere.com>

Cor and Kejpa,

I really don't care what kind of timers I'm using, the only thing I'm
after
is that they don't tick while code is executing doing other events.
Unfortunately I'm willing to bet none of them stop when a message box is
popped up. That's what I'd like, but I'm probably just going to have to
subclass all my timers, then make a custom message box class, and have the
two classes communicate with static methods. I want to avoid adding this
level of complexity if I can help it, but I'm not sure there's any other
way.

Bob

Nov 21 '05 #12

P: n/a
Bob
Yes, I posted a message on a previous "thread" (pun intended) but it was
more about whether or not to use threading at all. I've pretty much settled
on not using threading if I can help it, but ran into the message box
problem in the middle of finally committing to the single-thread design.
Unfortunately blocking reentry on the instance level is not enough, there
may be many timers; I'm thinking of using a static property. That takes me
90% of the way there.... actually that might be enough and I might not have
to worry about subclassing message boxes at all.

Thanks for helping me think a bit.
Bob

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:eY**************@tk2msftngp13.phx.gbl...
Bob,
Didn't you ask this question on Sept 29th 2004?

http://groups.google.com/groups?hl=e...TNGP11.phx.gbl
I'm not sure if these threads will help you or not:

http://groups.google.com/groups?hl=e...eb%25404ax.com
http://groups.google.com/groups?hl=e...TNGP12.phx.gbl

Rather then brew your own message box, I would have a well known object (a
Singleton, either the MainForm or my ApplicationContext singleton) have a
pair of methods that "locked" out the Timer events. Alternatively I would
code the Timer events so they were not reentrant (by checking a Static
variable in the method, the third link above has a sample).

Normally I simply code my Timer events so they are not reentrant.

Hope this helps
Jay

Nov 21 '05 #13

P: n/a
Bob,
may be many timers; I'm thinking of using a static property. A static property of what?

In the case of many timers, I would consider making a static (Shared)
property of a custom Timer class. That enabled raising Timer.Tick events.

Something like:

Public Class TimerEx
Inherits System.Windows.Forms.Timer

Private Shared m_eventsEnabled As Boolean

Public Shared Property EventsEnabled() As Boolean
Get
Return m_eventsEnabled
End Get
Set(ByVal value As Boolean)
m_eventsEnabled = value
End Set
End Property

Protected Overrides Sub OnTick(ByVal e As System.EventArgs)
If m_eventsEnabled Then
MyBase.OnTick(e)
End If
End Sub

End Class

Then on my forms I would use a TimerEx instead of Timer.

When TimerEx.EventsEnabled is False, no timer will raise its events, if
TimerEx.EventsEnabled is True then all timers will raise their events.

However! I normally favor Threading over using Timers to mimic Threading.

Hope this helps
Jay

"Bob" <no***@nowhere.com> wrote in message
news:Ow**************@TK2MSFTNGP14.phx.gbl... Yes, I posted a message on a previous "thread" (pun intended) but it was
more about whether or not to use threading at all. I've pretty much
settled
on not using threading if I can help it, but ran into the message box
problem in the middle of finally committing to the single-thread design.
Unfortunately blocking reentry on the instance level is not enough, there
may be many timers; I'm thinking of using a static property. That takes me
90% of the way there.... actually that might be enough and I might not
have
to worry about subclassing message boxes at all.

Thanks for helping me think a bit.
Bob

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:eY**************@tk2msftngp13.phx.gbl...
Bob,
Didn't you ask this question on Sept 29th 2004?

http://groups.google.com/groups?hl=e...TNGP11.phx.gbl

I'm not sure if these threads will help you or not:

http://groups.google.com/groups?hl=e...eb%25404ax.com

http://groups.google.com/groups?hl=e...TNGP12.phx.gbl


Rather then brew your own message box, I would have a well known object
(a
Singleton, either the MainForm or my ApplicationContext singleton) have a
pair of methods that "locked" out the Timer events. Alternatively I would
code the Timer events so they were not reentrant (by checking a Static
variable in the method, the third link above has a sample).

Normally I simply code my Timer events so they are not reentrant.

Hope this helps
Jay


Nov 21 '05 #14

This discussion thread is closed

Replies have been disabled for this discussion.