Sometimes control responds event twice.

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Locked
ivan.liao@live.com
Posts: 13
Joined: Sat Mar 09, 2019 4:47 am

Sometimes control responds event twice.

Post by ivan.liao@live.com »

Good day, everyone here.

I use PowerShell Studio 2019 5.6.160.0 to create a WPF project.
I found sometimes a control will responds event twice.
For example, I have a button. Added click event for it. Event to show a message, when I run and click on this button. Don't know why message shown twice.

I have to delete this control from my project and then recreate a new one, then the issue will be gone.
But sometimes it looks like does not work for just delete this control. I need to delete this control and its parent control.

Does anyone know what happen?

jvierra
Posts: 14452
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Sometimes control responds event twice.

Post by jvierra »

There is no reason for this. PowerShell Studio does not support WPF so you must have had coded it. I suspect you are adding the click event twice in your code.

ivan.liao@live.com
Posts: 13
Joined: Sat Mar 09, 2019 4:47 am

Re: Sometimes control responds event twice.

Post by ivan.liao@live.com »

jvierra wrote:
Tue Feb 25, 2020 9:44 pm
There is no reason for this. PowerShell Studio does not support WPF so you must have had coded it. I suspect you are adding the click event twice in your code.
Thanks for you reply!
I added only one button and one click event in my code.
But don't know why it will have twice after deployed. I can find duplicated button and event in XXX.Package.ps1.
That's strange.

jvierra
Posts: 14452
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Sometimes control responds event twice.

Post by jvierra »

This can only happen if you have an error in your code. I cannot see your code so there is no way to help you with this.

ivan.liao@live.com
Posts: 13
Joined: Sat Mar 09, 2019 4:47 am

Re: Sometimes control responds event twice.

Post by ivan.liao@live.com »

jvierra wrote:
Tue Feb 25, 2020 9:55 pm
This can only happen if you have an error in your code. I cannot see your code so there is no way to help you with this.
Each control I added only one in designer, but don't know why it added twice after deployed.

I use cygwin grep to find out which control have been added twice after deployed here, seems lots of control have this issue.

Here is some of the output:
➤ grep '^ # ' XXXX.Package.ps1 | sort
# --End User Generated Script--
# --End User Generated Script--
# Declare Global Variables and Functions here
# User Generated Script
# User Generated Script
# btnAllServers
# btnAllServers
# btnNextDay
# btnNextDay
# btnPreviousDay
# btnPreviousDay
# btnSvcReset
# btnSvcReset
# cbSvcAdmin
# cbSvcAdmin
# cbSvcAll
# cbSvcAll

Locked