473,320 Members | 1,724 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

DoEvents not working

Hello,
Could someone give me a hint why my CancelPrint Logic won't work despite the
DoEvents ?

in form lvele declaration I have
Public Shared CancelPrint As Boolean

'Printing Logic
Do While rsAccount.EOF = False And CancelPrint = False
Application.DoEvents()
SelFormula = "{Socios.NumSocio} in " & Chr(34) &
rsAccount.Fields("NumSocio").Value & Chr(34) & " to " & Chr(34) &
rsAccount.Fields("NumSocio").Value & Chr(34)
Dim crptStatement As New crptStatements_ATH
If ChkNotificacion.CheckState = CheckState.Unchecked Then
crptStatement.Section7.SectionFormat.EnableSuppres s = True
Else
crptStatement.Section7.SectionFormat.EnableSuppres s = False
End If
crptStatement.RecordSelectionFormula = SelFormula
i = i + 1
ProgressBar1.Value = i
crptStatement.PrintToPrinter(1, False, 0, 0)
rsAccount.MoveNext()
Loop

If CancelPrint Then
MsgBox("Printing Canceled By User", MsgBoxStyle.Exclamation)
End If

Private Sub CmdCancel_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles
'This togles the CancelPrint flag
CmdCancel.Click
CancelPrint = True
End Sub
Nov 20 '05 #1
50 2416
Hi P,

If I am right, do than not hit to hard against your head.

I think that If is never tested, just placing the loop a little bit lower
will maybe help.

Cor

i = i + 1
ProgressBar1.Value = i
crptStatement.PrintToPrinter(1, False, 0, 0)
rsAccount.MoveNext()
If CancelPrint Then
MsgBox("Printing Canceled By User", MsgBoxStyle.Exclamation)
End If
Loop
Nov 20 '05 #2
* "P. Prosper" <mo**************@moca-coop.com> scripsit:
Could someone give me a hint why my CancelPrint Logic won't work despite the
DoEvents ?

in form lvele declaration I have
Public Shared CancelPrint As Boolean


Why is 'CancelPrint' shared?

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #3
to be honest ....
CancelPrint is shared out of despair :-). Nevertheless this should work
anyway (or not ?).

about Cor's suggestion ...
If CancelPrint Then
MsgBox("Printing Canceled By User", MsgBoxStyle.Exclamation)
End If
is just a mean to notify the user that printing was canceled ..

the problem is that the event ...
Private Sub CmdCancel_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles CmdCancel.Click

CancelPrint = True

End Sub

is not being trigered in spite of the DoEvents()

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:c6************@ID-208219.news.uni-berlin.de...
* "P. Prosper" <mo**************@moca-coop.com> scripsit:
Could someone give me a hint why my CancelPrint Logic won't work despite the DoEvents ?

in form lvele declaration I have
Public Shared CancelPrint As Boolean


Why is 'CancelPrint' shared?

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 20 '05 #4
in fact if I just rem out crptStatement.PrintToPrinter(1, False, 0, 0)
the code works ..."sometimes" provided I click the cancel Button fast enough
<g>

"P. Prosper" <mo**************@moca-coop.com> wrote in message
news:OU*************@TK2MSFTNGP12.phx.gbl...
to be honest ....
CancelPrint is shared out of despair :-). Nevertheless this should work
anyway (or not ?).

about Cor's suggestion ...
If CancelPrint Then
MsgBox("Printing Canceled By User", MsgBoxStyle.Exclamation)
End If
is just a mean to notify the user that printing was canceled ..

the problem is that the event ...
Private Sub CmdCancel_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles CmdCancel.Click

CancelPrint = True

End Sub

is not being trigered in spite of the DoEvents()

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:c6************@ID-208219.news.uni-berlin.de...
* "P. Prosper" <mo**************@moca-coop.com> scripsit:
Could someone give me a hint why my CancelPrint Logic won't work
despite
the DoEvents ?

in form lvele declaration I have
Public Shared CancelPrint As Boolean


Why is 'CancelPrint' shared?

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>


Nov 20 '05 #5
Hi P,

What is that cmdcancel is that a button or something?

(And maybe more are you sure that that process is running and not all is
sended to a buffer?)

I would set a counter on a form (assuming that there is a form, so you can
see where it is)

Cor
Nov 20 '05 #6
yes CmdCancel is a button
"Cor Ligthert" <no**********@planet.nl> wrote in message
news:eY**************@tk2msftngp13.phx.gbl...
Hi P,

What is that cmdcancel is that a button or something?

(And maybe more are you sure that that process is running and not all is
sended to a buffer?)

I would set a counter on a form (assuming that there is a form, so you can
see where it is)

Cor

Nov 20 '05 #7
And that buffering?
yes CmdCancel is a button


Nov 20 '05 #8
* "P. Prosper" <mo**************@moca-coop.com> scripsit:
to be honest ....
CancelPrint is shared out of despair :-). Nevertheless this should work
anyway (or not ?).


I would expect your code to work.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #9
* "P. Prosper" <mo**************@moca-coop.com> scripsit:
Could someone give me a hint why my CancelPrint Logic won't work despite the
DoEvents ?


Just for my information: What doesn't work? Doesn't it cancel or is no
messagebox shown?

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #10
It just won't cancel ... wich is of paramount importance giving that app
will be printing anywhere from 1,500 to 2,000 statements <g>.
I wonder if will have to use some complex threading scheme to get it to
work, I'd hate to do that ...

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:c6************@ID-208219.news.uni-berlin.de...
* "P. Prosper" <mo**************@moca-coop.com> scripsit:
Could someone give me a hint why my CancelPrint Logic won't work despite the DoEvents ?


Just for my information: What doesn't work? Doesn't it cancel or is no
messagebox shown?

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 20 '05 #11
* "P. Prosper" <mo**************@moca-coop.com> scripsit:
It just won't cancel ... wich is of paramount importance giving that app
will be printing anywhere from 1,500 to 2,000 statements <g>.
I wonder if will have to use some complex threading scheme to get it to
work, I'd hate to do that ...


Did you try to output the cancel variable's value? Is it really set to
'True'?

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #12
The problem is that the loop is blocking the CmdCancel click event from
happening

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:c6************@ID-208219.news.uni-berlin.de...
* "P. Prosper" <mo**************@moca-coop.com> scripsit:
It just won't cancel ... wich is of paramount importance giving that app
will be printing anywhere from 1,500 to 2,000 statements <g>.
I wonder if will have to use some complex threading scheme to get it to
work, I'd hate to do that ...


Did you try to output the cancel variable's value? Is it really set to
'True'?

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 20 '05 #13
* "P. Prosper" <mo**************@moca-coop.com> scripsit:
The problem is that the loop is blocking the CmdCancel click event from
happening


You may want to put the loop into a separate thread (keyword:
multithreading).

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #14
Hi Herfried,
You may want to put the loop into a separate thread (keyword:
multithreading).


For looping through less than 10000 records in a recordset and trying to
stop that with a button?

Than it will be even more impossible in my opinion.

Cor
Nov 20 '05 #15
"Cor Ligthert" <no**********@planet.nl> schrieb

Than it will be even more impossible in my opinion.


"more impossible" is nice. :-)
--
Armin

Nov 20 '05 #16
Hi Herfried,
You may want to put the loop into a separate thread (keyword:
multithreading).


For looping through less than 10000 records in a recordset and trying to
stop that with a button?

Than it will be even more impossible in my opinion.

Cor
Nov 20 '05 #17
"Cor Ligthert" <no**********@planet.nl> schrieb

Than it will be even more impossible in my opinion.


"more impossible" is nice. :-)
--
Armin

Nov 20 '05 #18
* "Cor Ligthert" <no**********@planet.nl> scripsit:
You may want to put the loop into a separate thread (keyword:
multithreading).


For looping through less than 10000 records in a recordset and trying to
stop that with a button?

Than it will be even more impossible in my opinion.


What? The OP's code is blocking events from being processed, and
'Application.DoEvents' doesn't seem to help in his case.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #19
"P. Prosper" <mo**************@moca-coop.com> schrieb
The problem is that the loop is blocking the CmdCancel click event
from happening


Is the button enabled? Does the button change the visual state when holding
down the mouse? Have you already tried setting a breakpoint in the click
event handler? Do you use Debug or Release configuration? Is the
"Handles" clause still there? Is it's name really cmdCancel? Is there any
interaction reaction while printing?
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #20
* "Cor Ligthert" <no**********@planet.nl> scripsit:
You may want to put the loop into a separate thread (keyword:
multithreading).


For looping through less than 10000 records in a recordset and trying to
stop that with a button?

Than it will be even more impossible in my opinion.


What? The OP's code is blocking events from being processed, and
'Application.DoEvents' doesn't seem to help in his case.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #21
"P. Prosper" <mo**************@moca-coop.com> schrieb
The problem is that the loop is blocking the CmdCancel click event
from happening


Is the button enabled? Does the button change the visual state when holding
down the mouse? Have you already tried setting a breakpoint in the click
event handler? Do you use Debug or Release configuration? Is the
"Handles" clause still there? Is it's name really cmdCancel? Is there any
interaction reaction while printing?
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #22
For looping through less than 10000 records in a recordset and trying to
stop that with a button?

Than it will be even more impossible in my opinion.


What? The OP's code is blocking events from being processed, and
'Application.DoEvents' doesn't seem to help in his case.

Only when he is not fast enough with clicking he said read the complete
thread please.

Cor
Nov 20 '05 #23
* "Cor Ligthert" <no**********@planet.nl> scripsit:
For looping through less than 10000 records in a recordset and trying to
stop that with a button?

Than it will be even more impossible in my opinion.


What? The OP's code is blocking events from being processed, and
'Application.DoEvents' doesn't seem to help in his case.


Only when he is not fast enough with clicking he said read the complete
thread please.


Be sure that I read the thread. The problem will go away when using
multithreading.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #24
For looping through less than 10000 records in a recordset and trying to
stop that with a button?

Than it will be even more impossible in my opinion.


What? The OP's code is blocking events from being processed, and
'Application.DoEvents' doesn't seem to help in his case.

Only when he is not fast enough with clicking he said read the complete
thread please.

Cor
Nov 20 '05 #25
* "Cor Ligthert" <no**********@planet.nl> scripsit:
For looping through less than 10000 records in a recordset and trying to
stop that with a button?

Than it will be even more impossible in my opinion.


What? The OP's code is blocking events from being processed, and
'Application.DoEvents' doesn't seem to help in his case.


Only when he is not fast enough with clicking he said read the complete
thread please.


Be sure that I read the thread. The problem will go away when using
multithreading.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #26
Hi Hefried,

Be sure that I read the thread. The problem will go away when using
multithreading.


Show me where this will help, I changed the code to make it testable, this
works very good.
However when I bring the loop down to 10000 it is almost impossible to reach
the cancel button.

So show me what the multithread can do to help this with a loop of 2000
records in the dataset, without slowing the loop down.(The recordset loop
needs probably much less time, because there is no screen painting)

I spent some time on it, so I expect an answer.

Cor

\\\
Private CancelPrint As Boolean
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Me.Button1.Text = "Start"
Me.ProgressBar1.Maximum = 1000000
Me.ProgressBar1.Value = 1
End Sub
Private Sub CmdCancel_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button2.Click
CancelPrint = True
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Dim a As Integer
CancelPrint = False
Button2.Focus()
Do While ProgressBar1.Value < ProgressBar1.Maximum _
And CancelPrint = False
Application.DoEvents()
ProgressBar1.Value += 1
Loop
If CancelPrint Then
MsgBox("Printing Canceled By User", MsgBoxStyle.Exclamation)
End If
End Sub
///
Nov 20 '05 #27
Hi Hefried,

Be sure that I read the thread. The problem will go away when using
multithreading.


Show me where this will help, I changed the code to make it testable, this
works very good.
However when I bring the loop down to 10000 it is almost impossible to reach
the cancel button.

So show me what the multithread can do to help this with a loop of 2000
records in the dataset, without slowing the loop down.(The recordset loop
needs probably much less time, because there is no screen painting)

I spent some time on it, so I expect an answer.

Cor

\\\
Private CancelPrint As Boolean
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Me.Button1.Text = "Start"
Me.ProgressBar1.Maximum = 1000000
Me.ProgressBar1.Value = 1
End Sub
Private Sub CmdCancel_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button2.Click
CancelPrint = True
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Dim a As Integer
CancelPrint = False
Button2.Focus()
Do While ProgressBar1.Value < ProgressBar1.Maximum _
And CancelPrint = False
Application.DoEvents()
ProgressBar1.Value += 1
Loop
If CancelPrint Then
MsgBox("Printing Canceled By User", MsgBoxStyle.Exclamation)
End If
End Sub
///
Nov 20 '05 #28
* "Cor Ligthert" <no**********@planet.nl> scripsit:
Be sure that I read the thread. The problem will go away when using
multithreading.
Show me where this will help, I changed the code to make it testable, this
works very good.
However when I bring the loop down to 10000 it is almost impossible to reach
the cancel button.


The OP didn't tell us how long the loop takes to execute.
So show me what the multithread can do to help this with a loop of 2000
records in the dataset, without slowing the loop down.(The recordset loop
needs probably much less time, because there is no screen painting)


It depends on what you are actually doing with the data.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #29
>
The OP didn't tell us how long the loop takes to execute.

Did you ask it to him?

I asked however he did not give an answer on that, after he got the right
answer from MVP Herfried K. Wagner that to use applications.doevents it
absolutly is necessary to use as well multithreading.

And do not say you did not say, you did explicitly said that 2 or more
times.

Cor
Nov 20 '05 #30
* "Cor Ligthert" <no**********@planet.nl> scripsit:
Be sure that I read the thread. The problem will go away when using
multithreading.
Show me where this will help, I changed the code to make it testable, this
works very good.
However when I bring the loop down to 10000 it is almost impossible to reach
the cancel button.


The OP didn't tell us how long the loop takes to execute.
So show me what the multithread can do to help this with a loop of 2000
records in the dataset, without slowing the loop down.(The recordset loop
needs probably much less time, because there is no screen painting)


It depends on what you are actually doing with the data.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #31
* "Cor Ligthert" <no**********@planet.nl> scripsit:
The OP didn't tell us how long the loop takes to execute.
Did you ask it to him?


No.
I asked however he did not give an answer on that, after he got the right
answer from MVP Herfried K. Wagner that to use applications.doevents it
absolutly is necessary to use as well multithreading.


LOL!

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #32
>
The OP didn't tell us how long the loop takes to execute.

Did you ask it to him?

I asked however he did not give an answer on that, after he got the right
answer from MVP Herfried K. Wagner that to use applications.doevents it
absolutly is necessary to use as well multithreading.

And do not say you did not say, you did explicitly said that 2 or more
times.

Cor
Nov 20 '05 #33
* "Cor Ligthert" <no**********@planet.nl> scripsit:
The OP didn't tell us how long the loop takes to execute.
Did you ask it to him?


No.
I asked however he did not give an answer on that, after he got the right
answer from MVP Herfried K. Wagner that to use applications.doevents it
absolutly is necessary to use as well multithreading.


LOL!

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #34
Hello both,
Sorry I was away for the weekend
to clarify the situation ...
I agree that iterating through 10000 records would not give me the time to
click the button. But as posted in my initial Post, the loop take over 10
minutes to complete (thanks to the lines wher crptStatement (crystal report
statement) appear)

yes the button is enabled . I did try setting a break in the button click
event but it does'nt even get there.
I tried :
If i = 100 Then

CmdCancel.PerformClick()

'End If

inside the loop and the logic does work. It's seems as if the crystal report
is blocking the thread to the point where the click event does'nt get
executed.
Dim crptStatement As New crptStatements_ATH
If ChkNotificacion.CheckState = CheckState.Unchecked Then
crptStatement.Section7.SectionFormat.EnableSuppres s = True
Else
crptStatement.Section7.SectionFormat.EnableSuppres s = False
End If
crptStatement.RecordSelectionFormula = SelFormula
i = i + 1
ProgressBar1.Value = i
crptStatement.PrintToPrinter(1, False, 0, 0)

"Armin Zingler" <az*******@freenet.de> wrote in message
news:40*********************@news.freenet.de...
"P. Prosper" <mo**************@moca-coop.com> schrieb
The problem is that the loop is blocking the CmdCancel click event
from happening
Is the button enabled? Does the button change the visual state when

holding down the mouse? Have you already tried setting a breakpoint in the click
event handler? Do you use Debug or Release configuration? Is the
"Handles" clause still there? Is it's name really cmdCancel? Is there any
interaction reaction while printing?
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #35
"P. Prosper" <mo**************@moca-coop.com> schrieb
Hello both,
Sorry I was away for the weekend
to clarify the situation ...
I agree that iterating through 10000 records would not give me the
time to click the button. But as posted in my initial Post, the loop
take over 10 minutes to complete (thanks to the lines wher
crptStatement (crystal report statement) appear)

yes the button is enabled . I did try setting a break in the button
click event but it does'nt even get there.
I tried :
If i = 100 Then

CmdCancel.PerformClick()

'End If

inside the loop and the logic does work. It's seems as if the crystal
report is blocking the thread to the point where the click event
does'nt get executed.


DoEvents should be sufficient to be able to click the button.

I'm still interested in: Does the button change the visual state when
holding down the mouse?

Maybe the form looses focus when CR starts printing.
Replace a single call of application.doevents by this (only for testing):

dim start as integer
start = environment.tickcount

do
application.doevents
loop until environment.tickcount - start > 2000 orelse CancelPrint

if cancelprint then stop
Try again and see if the button can be clicked and the stop statement is
reached.
Don't forget to remove your CmdCancel.PerformClick. ;-)
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #36
IT WORKS :-) !!!!
Before inserting your lines, Armin, the button would'nt change it's visual
state while clicking (all I had was a flashing hourglass cursor). It also
works if I insert the following lines inside the loop
Dim x As Integer

For x = 0 To 200

Application.DoEvents()

Next x

I's a performance hit but anyway the user has to wait for the printer to
digest the print jobs.

Seems that DoEvents does NOT process all the events in the queue after all.
I'm still puzzled why it would.nt work in the first place.

Thank you all so very much :-)

"Armin Zingler" <az*******@freenet.de> wrote in message
news:40***********************@news.freenet.de...
"P. Prosper" <mo**************@moca-coop.com> schrieb
Hello both,
Sorry I was away for the weekend
to clarify the situation ...
I agree that iterating through 10000 records would not give me the
time to click the button. But as posted in my initial Post, the loop
take over 10 minutes to complete (thanks to the lines wher
crptStatement (crystal report statement) appear)

yes the button is enabled . I did try setting a break in the button
click event but it does'nt even get there.
I tried :
If i = 100 Then

CmdCancel.PerformClick()

'End If

inside the loop and the logic does work. It's seems as if the crystal
report is blocking the thread to the point where the click event
does'nt get executed.


DoEvents should be sufficient to be able to click the button.

I'm still interested in: Does the button change the visual state when
holding down the mouse?

Maybe the form looses focus when CR starts printing.
Replace a single call of application.doevents by this (only for testing):

dim start as integer
start = environment.tickcount

do
application.doevents
loop until environment.tickcount - start > 2000 orelse CancelPrint

if cancelprint then stop
Try again and see if the button can be clicked and the stop statement is
reached.
Don't forget to remove your CmdCancel.PerformClick. ;-)
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #37
* "P. Prosper" <mo**************@moca-coop.com> scripsit:
IT WORKS :-) !!!!
Before inserting your lines, Armin, the button would'nt change it's visual
state while clicking (all I had was a flashing hourglass cursor). It also
works if I insert the following lines inside the loop
Dim x As Integer

For x = 0 To 200

Application.DoEvents()

Next x

I's a performance hit but anyway the user has to wait for the printer to
digest the print jobs.

Seems that DoEvents does NOT process all the events in the queue after all.
I'm still puzzled why it would.nt work in the first place.


IMO performing all the stuff in a separate thread and checking a Boolean
variable that is set on button click is still the cleaner solution ;-).

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #38
Hi Herfried,

IMO performing all the stuff in a separate thread and checking a Boolean
variable that is set on button click is still the cleaner solution ;-).

For printing it can be a nicer solution. However when there is need to print
first and than go on with the solution than not.

And the multithreading had not resolved the problem, it had made it even
more complex and that is always the wrong way to go to resolve a problem.

Cor
Nov 20 '05 #39
"P. Prosper" <mo**************@moca-coop.com> schrieb
IT WORKS :-) !!!!
Before inserting your lines, Armin, the button would'nt change it's
visual state while clicking (all I had was a flashing hourglass
cursor). It also works if I insert the following lines inside the
loop
Dim x As Integer

For x = 0 To 200

Application.DoEvents()

Next x

I's a performance hit but anyway the user has to wait for the
printer to digest the print jobs.

Seems that DoEvents does NOT process all the events in the queue
after all. I'm still puzzled why it would.nt work in the first
place.

Thank you all so very much :-)


[Wanted to send this yesterday, but...]

Good to know it works now. Though, I'm intersted in why. I made the
suggestion because I believed to remember a short "printing page ..."
message coming from CR. If this was true, the Form (and the button) would
loose the focus for a very short period of time. If this happens while you
are holding down the button you won't get a click event anymore - unless you
press and release the moust button fast enough to be processed in a single
call to application.doevents. ;-) Still this is speculation. You could
handle the Button's lostfocus event to check this (debug.writeline
"lostfocus").

....

Meanwhile I tried to reproduce the problem (why not earlier?). The only
thing that came back into my mind was a different bug: If you try to click a
button during a loop containing application.doevents, not the button itself
is clicked but the button currently having the focus.

Anyway, while testing, my Button does not loose the focus and I can click
it. So my speculation was wrong... Sorry, I wished I found the solution.
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
Nov 20 '05 #40
Hi Armin,

That lost focus I have also seen, that button.focus is in my sample to
Herfried too.
(Which not solves the problem by the way, that was your solution.)

Cor
Nov 20 '05 #41
* "Cor Ligthert" <no**********@planet.nl> scripsit:
IMO performing all the stuff in a separate thread and checking a Boolean
variable that is set on button click is still the cleaner solution ;-). [...]

And the multithreading had not resolved the problem, it had made it even
more complex and that is always the wrong way to go to resolve a problem.


Multithreading doesn't make it more complex, but you can better separate
the UI from data processing.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #42
Herfried,
Multithreading doesn't make it more complex, but you can better separate
the UI from data processing.


We make both a solution.

Show on a form the result in a label from the process 1 + 1

You use multithreading I not, let us look what is less complex.

However I think you are afraid to take this chalenge.

Cor
Nov 20 '05 #43
>
Show on a form the result in a label from the process 1 + 1

private sub form load ...........
me.label.text= 1+1
end sub

I am curious for your multithreading solution

Cor
Nov 20 '05 #44
Hi Herfried,

While I made my solution I forgot I wrote this nowhere in this thread.
Multithreading doesn't make it more complex, but you can better separate
the UI from data processing.

Multithreading makes the total processing time and the use of resources much
longer/higher when there is no external waiting time involved.

And therefore your statement is bs

A good sample for multithreading is printing when it is about huge printing
where the buffer is not able to process in time the printing. However
remoting is than even better.

Cor
Nov 20 '05 #45
* "Cor Ligthert" <no**********@planet.nl> scripsit:
Show on a form the result in a label from the process 1 + 1


private sub form load ...........
me.label.text= 1+1
end sub

I am curious for your multithreading solution


You are joking, aren't you?

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #46
Cor,

* "Cor Ligthert" <no**********@planet.nl> scripsit:
Multithreading doesn't make it more complex, but you can better separate
the UI from data processing.

Multithreading makes the total processing time and the use of resources much
longer/higher when there is no external waiting time involved.


I don't see any reasons for that. IMO that's a typical case for
multithreading.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #47
Cor,

* "Cor Ligthert" <no**********@planet.nl> scripsit:
Multithreading doesn't make it more complex, but you can better separate
the UI from data processing.
We make both a solution.


I don't have enough time to do that.
Show on a form the result in a label from the process 1 + 1

You use multithreading I not, let us look what is less complex.
Mhm... I never said that there are any advantages with mutithreading if
there is a simple '1 + 1' calculcation in a loop. It's all about
/heavy/ working, like in the OP's case where the task takes about 10
minutes.
However I think you are afraid to take this chalenge.


I am not afraid, but I am not sure how you would like to interpret the
result? Even if the multithreading solution is slower, I don't think
that's a big problem, if the overall user experience is better.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #48
Hi Herfried,

I am joking of course, however see my sample.

What I try to say to you is that there are situations where multithreading
is good to use. And that is where there are much seperated parallel
processes where the sum of the processes make the result.

However in a sequential proces the single thread is always more efficient
because there is no threadmanagement needed.

When the sum of the processes is not important, than is remoting much more
efficient when there are parallel or especial semiparallel processes.
(However for most people to difficult to implement)

Cor
Nov 20 '05 #49
Thought the thread was dead, but I guess I was wrong LOL ..
The truth is that putting a DoEvents in a loop fixed the problem this time
but I know I'll bump into the problem in the future again.

Again I'm still puzzled why it didn't work in the first place.

I haven't notice the "printing page ..." message. Also, I tried your
suggestion on setting a trap in the LostFocus event of CmdCancel but the
button did not lose focus (I did CmdCancel.Focus before entering the loop).

"Armin Zingler" <az*******@freenet.de> wrote in message
news:40***********************@news.freenet.de...
"P. Prosper" <mo**************@moca-coop.com> schrieb
IT WORKS :-) !!!!
Before inserting your lines, Armin, the button would'nt change it's
visual state while clicking (all I had was a flashing hourglass
cursor). It also works if I insert the following lines inside the
loop
Dim x As Integer

For x = 0 To 200

Application.DoEvents()

Next x

I's a performance hit but anyway the user has to wait for the
printer to digest the print jobs.

Seems that DoEvents does NOT process all the events in the queue
after all. I'm still puzzled why it would.nt work in the first
place.

Thank you all so very much :-)
[Wanted to send this yesterday, but...]

Good to know it works now. Though, I'm intersted in why. I made the
suggestion because I believed to remember a short "printing page ..."
message coming from CR. If this was true, the Form (and the button) would
loose the focus for a very short period of time. If this happens while you
are holding down the button you won't get a click event anymore - unless

you press and release the moust button fast enough to be processed in a single
call to application.doevents. ;-) Still this is speculation. You could
handle the Button's lostfocus event to check this (debug.writeline
"lostfocus").

...

Meanwhile I tried to reproduce the problem (why not earlier?). The only
thing that came back into my mind was a different bug: If you try to click a button during a loop containing application.doevents, not the button itself is clicked but the button currently having the focus.

Anyway, while testing, my Button does not loose the focus and I can click
it. So my speculation was wrong... Sorry, I wished I found the solution.
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #50

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

Similar topics

0
by: Jon Lewis | last post by:
I'm trying to make a 'Working' dialog with a rotating hourglass which displays during a long process. The dialog says hit <Esc> to cancel the process. If <Esc> is hit, the 'Process' ends and...
6
by: Ollie Riches | last post by:
I understand the use of Application.DoEvents() to process all outstanding messages on the message queue in a winforms application if you have long running process on the UI thread. But can anyone...
17
by: Lance | last post by:
I've noticed that calling DoEvents is much slower in an application that has called Application.EnableVisualStyles in Sub Main. Furthermore, the performance seems to worsen each time that DoEvents...
12
by: Jack Russell | last post by:
My unstanding of all VB up to and including vb6 is that an event could not "interrupt" itself. For instance if you had a timer event containing a msgbox then you would only get one message. ...
0
by: Mika M | last post by:
Hi! I'm using Rs232-class, which was shipped with 101 VB.NET samples by Microsoft. Application is made to read COM-port with the following code... Try Me.tmrReadCommPort.Enabled = True If...
8
by: TrtnJohn | last post by:
I have an application where I would like to block waiting on an asynchronous event and still process messages. I can implement a hard loop to block such as: Do While StillWaiting...
3
by: Dennis | last post by:
I find myself having to use Application.DoEvents to clear out my program events before proceeding to the next line of code, especially when working with MCI and using "NOTIFY" callback. Is this...
5
by: james.jdunne | last post by:
System.ArgumentException: Item has already been added. Key in dictionary: "-1" Key being added: "-1" at System.Collections.Hashtable.Insert(Object key, Object nvalue, Boolean add) at...
12
by: Justin | last post by:
I can attach my code if anyone wants to see it however I'll try to ask my question with some mark up code first. I'm having a problem terminating my process while using DoEvents. For example: ...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.