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 | | | | re: DoEvents not working
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 | | | | re: DoEvents not working
* "P. Prosper" <mocanoREMOVETHIS@moca-coop.com> scripsit:[color=blue]
> 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[/color]
Why is 'CancelPrint' shared?
--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/> | | | | re: DoEvents not working
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]" <hirf-spam-me-here@gmx.at> wrote in message
news:c6u33h$bhamc$1@ID-208219.news.uni-berlin.de...[color=blue]
> * "P. Prosper" <mocanoREMOVETHIS@moca-coop.com> scripsit:[color=green]
> > Could someone give me a hint why my CancelPrint Logic won't work despite[/color][/color]
the[color=blue][color=green]
> > DoEvents ?
> >
> > in form lvele declaration I have
> > Public Shared CancelPrint As Boolean[/color]
>
> Why is 'CancelPrint' shared?
>
> --
> Herfried K. Wagner [MVP]
> <URL:http://dotnet.mvps.org/>[/color] | | | | re: DoEvents not working
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" <mocanoREMOVETHIS@moca-coop.com> wrote in message
news:OULMdPuLEHA.160@TK2MSFTNGP12.phx.gbl...[color=blue]
> 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]" <hirf-spam-me-here@gmx.at> wrote in message
> news:c6u33h$bhamc$1@ID-208219.news.uni-berlin.de...[color=green]
> > * "P. Prosper" <mocanoREMOVETHIS@moca-coop.com> scripsit:[color=darkred]
> > > Could someone give me a hint why my CancelPrint Logic won't work[/color][/color][/color]
despite[color=blue]
> the[color=green][color=darkred]
> > > DoEvents ?
> > >
> > > in form lvele declaration I have
> > > Public Shared CancelPrint As Boolean[/color]
> >
> > Why is 'CancelPrint' shared?
> >
> > --
> > Herfried K. Wagner [MVP]
> > <URL:http://dotnet.mvps.org/>[/color]
>
>[/color] | | | | re: DoEvents not working
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 | | | | re: DoEvents not working
yes CmdCancel is a button
"Cor Ligthert" <notfirstname@planet.nl> wrote in message
news:eYNeaXuLEHA.3596@tk2msftngp13.phx.gbl...[color=blue]
> 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
>
>[/color] | | | | re: DoEvents not working
And that buffering?
[color=blue]
> yes CmdCancel is a button[/color] | | | | re: DoEvents not working
* "P. Prosper" <mocanoREMOVETHIS@moca-coop.com> scripsit:[color=blue]
> to be honest ....
> CancelPrint is shared out of despair :-). Nevertheless this should work
> anyway (or not ?).[/color]
I would expect your code to work.
--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/> | | | | re: DoEvents not working
* "P. Prosper" <mocanoREMOVETHIS@moca-coop.com> scripsit:[color=blue]
> Could someone give me a hint why my CancelPrint Logic won't work despite the
> DoEvents ?[/color]
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/> | | | | re: DoEvents not working
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]" <hirf-spam-me-here@gmx.at> wrote in message
news:c6u9p6$gda6a$2@ID-208219.news.uni-berlin.de...[color=blue]
> * "P. Prosper" <mocanoREMOVETHIS@moca-coop.com> scripsit:[color=green]
> > Could someone give me a hint why my CancelPrint Logic won't work despite[/color][/color]
the[color=blue][color=green]
> > DoEvents ?[/color]
>
> 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/>[/color] | | | | re: DoEvents not working
* "P. Prosper" <mocanoREMOVETHIS@moca-coop.com> scripsit:[color=blue]
> 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 ...[/color]
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/> | | | | re: DoEvents not working
The problem is that the loop is blocking the CmdCancel click event from
happening
"Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message
news:c6uhfl$gl29o$1@ID-208219.news.uni-berlin.de...[color=blue]
> * "P. Prosper" <mocanoREMOVETHIS@moca-coop.com> scripsit:[color=green]
> > 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 ...[/color]
>
> 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/>[/color] | | | | re: DoEvents not working
* "P. Prosper" <mocanoREMOVETHIS@moca-coop.com> scripsit:[color=blue]
> The problem is that the loop is blocking the CmdCancel click event from
> happening[/color]
You may want to put the loop into a separate thread (keyword:
multithreading).
--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/> | | | | re: DoEvents not working
Hi Herfried,
[color=blue]
> You may want to put the loop into a separate thread (keyword:
> multithreading).[/color]
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 | | | | re: DoEvents not working
"Cor Ligthert" <notfirstname@planet.nl> schrieb[color=blue]
>
> Than it will be even more impossible in my opinion.[/color]
"more impossible" is nice. :-)
--
Armin | | | | re: DoEvents not working
Hi Herfried,
[color=blue]
> You may want to put the loop into a separate thread (keyword:
> multithreading).[/color]
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 | | | | re: DoEvents not working
"Cor Ligthert" <notfirstname@planet.nl> schrieb[color=blue]
>
> Than it will be even more impossible in my opinion.[/color]
"more impossible" is nice. :-)
--
Armin | | | | re: DoEvents not working
* "Cor Ligthert" <notfirstname@planet.nl> scripsit:[color=blue][color=green]
>> You may want to put the loop into a separate thread (keyword:
>> multithreading).[/color]
>
> 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.[/color]
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/> | | | | re: DoEvents not working
"P. Prosper" <mocanoREMOVETHIS@moca-coop.com> schrieb[color=blue]
> The problem is that the loop is blocking the CmdCancel click event
> from happening[/color]
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 | | | | re: DoEvents not working
* "Cor Ligthert" <notfirstname@planet.nl> scripsit:[color=blue][color=green]
>> You may want to put the loop into a separate thread (keyword:
>> multithreading).[/color]
>
> 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.[/color]
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/> | | | | re: DoEvents not working
"P. Prosper" <mocanoREMOVETHIS@moca-coop.com> schrieb[color=blue]
> The problem is that the loop is blocking the CmdCancel click event
> from happening[/color]
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 | | | | re: DoEvents not working
[color=blue][color=green]
> > 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.[/color]
>
> What? The OP's code is blocking events from being processed, and
> 'Application.DoEvents' doesn't seem to help in his case.
>[/color]
Only when he is not fast enough with clicking he said read the complete
thread please.
Cor | | | | re: DoEvents not working
* "Cor Ligthert" <notfirstname@planet.nl> scripsit:[color=blue][color=green][color=darkred]
>>> 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.[/color]
>>
>> What? The OP's code is blocking events from being processed, and
>> 'Application.DoEvents' doesn't seem to help in his case.[/color]
>
> Only when he is not fast enough with clicking he said read the complete
> thread please.[/color]
Be sure that I read the thread. The problem will go away when using
multithreading.
--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/> | | | | re: DoEvents not working
[color=blue][color=green]
> > 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.[/color]
>
> What? The OP's code is blocking events from being processed, and
> 'Application.DoEvents' doesn't seem to help in his case.
>[/color]
Only when he is not fast enough with clicking he said read the complete
thread please.
Cor | | | | re: DoEvents not working
* "Cor Ligthert" <notfirstname@planet.nl> scripsit:[color=blue][color=green][color=darkred]
>>> 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.[/color]
>>
>> What? The OP's code is blocking events from being processed, and
>> 'Application.DoEvents' doesn't seem to help in his case.[/color]
>
> Only when he is not fast enough with clicking he said read the complete
> thread please.[/color]
Be sure that I read the thread. The problem will go away when using
multithreading.
--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/> | | | | re: DoEvents not working
Hi Hefried,
[color=blue]
> Be sure that I read the thread. The problem will go away when using
> multithreading.[/color]
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
/// | | | | re: DoEvents not working
Hi Hefried,
[color=blue]
> Be sure that I read the thread. The problem will go away when using
> multithreading.[/color]
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
/// | | | | re: DoEvents not working
* "Cor Ligthert" <notfirstname@planet.nl> scripsit:[color=blue][color=green]
>> Be sure that I read the thread. The problem will go away when using
>> multithreading.[/color]
>
> 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.[/color]
The OP didn't tell us how long the loop takes to execute.
[color=blue]
> 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)[/color]
It depends on what you are actually doing with the data.
--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/> | | | | re: DoEvents not working
>[color=blue]
> The OP didn't tell us how long the loop takes to execute.
>[/color]
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 | | | | re: DoEvents not working
* "Cor Ligthert" <notfirstname@planet.nl> scripsit:[color=blue][color=green]
>> Be sure that I read the thread. The problem will go away when using
>> multithreading.[/color]
>
> 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.[/color]
The OP didn't tell us how long the loop takes to execute.
[color=blue]
> 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)[/color]
It depends on what you are actually doing with the data.
--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/> | | | | re: DoEvents not working
* "Cor Ligthert" <notfirstname@planet.nl> scripsit:[color=blue][color=green]
>> The OP didn't tell us how long the loop takes to execute.[/color]
>
> Did you ask it to him?[/color]
No.
[color=blue]
> 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.[/color]
LOL!
--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/> | | | | re: DoEvents not working
>[color=blue]
> The OP didn't tell us how long the loop takes to execute.
>[/color]
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 | | | | re: DoEvents not working
* "Cor Ligthert" <notfirstname@planet.nl> scripsit:[color=blue][color=green]
>> The OP didn't tell us how long the loop takes to execute.[/color]
>
> Did you ask it to him?[/color]
No.
[color=blue]
> 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.[/color]
LOL!
--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/> | | | | re: DoEvents not working
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.nospam@freenet.de> wrote in message
news:4093ee8c$0$147$9b622d9e@news.freenet.de...[color=blue]
> "P. Prosper" <mocanoREMOVETHIS@moca-coop.com> schrieb[color=green]
> > The problem is that the loop is blocking the CmdCancel click event
> > from happening[/color]
>
> Is the button enabled? Does the button change the visual state when[/color]
holding[color=blue]
> 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
>[/color] | | | | re: DoEvents not working
"P. Prosper" <mocanoREMOVETHIS@moca-coop.com> schrieb[color=blue]
> 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.[/color]
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 | | | | re: DoEvents not working
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.nospam@freenet.de> wrote in message
news:40967187$0$13008$9b622d9e@news.freenet.de...[color=blue]
> "P. Prosper" <mocanoREMOVETHIS@moca-coop.com> schrieb[color=green]
> > 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.[/color]
>
> 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
>
>
>[/color] | | | | re: DoEvents not working
* "P. Prosper" <mocanoREMOVETHIS@moca-coop.com> scripsit:[color=blue]
> 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.[/color]
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/> | | | | re: DoEvents not working
Hi Herfried,[color=blue]
>
> 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 ;-).
>[/color]
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 | | | | re: DoEvents not working
"P. Prosper" <mocanoREMOVETHIS@moca-coop.com> schrieb[color=blue]
> 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 :-)[/color]
[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 | | | | re: DoEvents not working
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 | | | | re: DoEvents not working
* "Cor Ligthert" <notfirstname@planet.nl> scripsit:[color=blue][color=green]
>> 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 ;-). [...][/color]
> 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.[/color]
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/> | | | | re: DoEvents not working
Herfried,
[color=blue]
> Multithreading doesn't make it more complex, but you can better separate
> the UI from data processing.[/color]
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 | | | | re: DoEvents not working
>[color=blue]
> Show on a form the result in a label from the process 1 + 1
>[/color]
private sub form load ...........
me.label.text= 1+1
end sub
I am curious for your multithreading solution
Cor | | | | re: DoEvents not working
Hi Herfried,
While I made my solution I forgot I wrote this nowhere in this thread.
[color=blue]
> Multithreading doesn't make it more complex, but you can better separate
> the UI from data processing.
>[/color]
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 | | | | re: DoEvents not working
* "Cor Ligthert" <notfirstname@planet.nl> scripsit:[color=blue][color=green]
>> Show on a form the result in a label from the process 1 + 1[/color]
>
> private sub form load ...........
> me.label.text= 1+1
> end sub
>
> I am curious for your multithreading solution[/color]
You are joking, aren't you?
--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/> | | | | re: DoEvents not working
Cor,
* "Cor Ligthert" <notfirstname@planet.nl> scripsit:[color=blue][color=green]
>> Multithreading doesn't make it more complex, but you can better separate
>> the UI from data processing.
>>[/color]
> Multithreading makes the total processing time and the use of resources much
> longer/higher when there is no external waiting time involved.[/color]
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/> | | | | re: DoEvents not working
Cor,
* "Cor Ligthert" <notfirstname@planet.nl> scripsit:[color=blue][color=green]
>> Multithreading doesn't make it more complex, but you can better separate
>> the UI from data processing.[/color]
>
> We make both a solution.[/color]
I don't have enough time to do that.
[color=blue]
> 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.[/color]
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.
[color=blue]
> However I think you are afraid to take this chalenge.[/color]
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/> | | | | re: DoEvents not working
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 | | | | re: DoEvents not working
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.nospam@freenet.de> wrote in message
news:40975a27$0$13025$9b622d9e@news.freenet.de...[color=blue]
> "P. Prosper" <mocanoREMOVETHIS@moca-coop.com> schrieb[color=green]
> > 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 :-)[/color]
>
> [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[/color]
you[color=blue]
> 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[/color]
a[color=blue]
> button during a loop containing application.doevents, not the button[/color]
itself[color=blue]
> 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
>
>[/color] |  | | Similar Visual Basic .NET bytes | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,471 network members.
|