Problem with form, wrong button pressed

G

Guest

Hello all,

I have a form and a button. The code for the button is as follows

Sub tProc()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim i
For i = 1 To 1000
Dim t As New System.Threading.Thread(AddressOf tProc)
t.Start()
While t.IsAlive = True
Application.DoEvents()
End While
Next
End Sub

The problem is that when I start my code by clicking the button, if I then
try
to click on the terminate button (top-right button of titlebar), then
instead
of it being depressed, my button is depressed, i.e. there is a mismatch
between
what I press and what I see on the screen.

Thanks in advance for any assistance.
 
A

Armin Zingler

Hello all,

I have a form and a button. The code for the button is as follows

Sub tProc()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim i
For i = 1 To 1000
Dim t As New System.Threading.Thread(AddressOf tProc)
t.Start()
While t.IsAlive = True
Application.DoEvents()
End While
Next
End Sub

The problem is that when I start my code by clicking the button, if
I then try
to click on the terminate button (top-right button of titlebar),
then instead
of it being depressed, my button is depressed, i.e. there is a
mismatch between
what I press and what I see on the screen.

Thanks in advance for any assistance.

That's a bug if you use application.doevents. No matter where you click,
even if it is the X to close the window, always the button is clicked.
Workaround: Alt+Tab away and go back, then it works.


Armin
 
R

rowe_newsgroups

Hello all,

I have a form and a button. The code for the button is as follows

Sub tProc()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim i
For i = 1 To 1000
Dim t As New System.Threading.Thread(AddressOf tProc)
t.Start()
While t.IsAlive = True
Application.DoEvents()
End While
Next
End Sub

The problem is that when I start my code by clicking the button, if I then
try
to click on the terminate button (top-right button of titlebar), then
instead
of it being depressed, my button is depressed, i.e. there is a mismatch
between
what I press and what I see on the screen.

Thanks in advance for any assistance.

It seems odd to me that you are starting a thread and just looping
till it finishes. It seems better to me to start the thread and exit
the procedure, and then have the thread raise an event when it
finishes. Since this approach would also do away with the DoEvents
call it would (in theory) eliminate your problem.

Thanks,

Seth Rowe
 
G

Guest

It seems odd to me that you are starting a thread and just looping
till it finishes. It seems better to me to start the thread and exit
the procedure, and then have the thread raise an event when it
finishes. Since this approach would also do away with the DoEvents
call it would (in theory) eliminate your problem.

Yes, I will do it, ... and let you know in a moment
 
G

Guest

Teali,

Are you sure you have the necessary background to be tackling threading?

Kerry Moorman
 
Q

Quivis

On 03 aug 2007,
=?Utf-8?B?S2VycnkgTW9vcm1hbg==?=<[email protected]
om>, had the following to say to the folks in
microsoft.public.dotnet.languages.vb:
Are you sure you have the necessary background to be tackling
threading?

Does that matter? It's his computer.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top