H0w to get Timer working with buttons

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.
This topic is 1 year and 8 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
IanBennett
Posts: 2
Last visit: Tue Jul 12, 2022 4:41 pm

H0w to get Timer working with buttons

Post by IanBennett »

Hi there
I am sure that this has been flogged to death and a solution is easy to be given.
What I am trying to do is to have a form display that will check for two Processes (TEAMS and MSTSC) and if they are both running display the form.
What I am then to do is show a countdown on the form (time to be set but currently I have it at 2 for testing) for the user to select one of the two processes to be stopped.
If they do not press one of the two within that time the form will stop the coded one and then close.
However if they press an option the process will stop and the form will close.
Now if I use $from.show the countdown works but not the buttons. If I use ShowDialog the buttons work but the countdown does not.
I am new to PS and so am not sure how to use the -parallel, Run statements or other smart ideas.
Attachments
StopProcess.ps1
(4.01 KiB) Downloaded 38 times
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: H0w to get Timer working with buttons

Post by jvierra »

There are a large number of articles available on the following link that will help you learn basic PowerShell. The menus at the top of this page have links to videos on YouTube that can also help to get you started with PowerShell.

https://info.sapien.com/
IanBennett
Posts: 2
Last visit: Tue Jul 12, 2022 4:41 pm

Re: H0w to get Timer working with buttons

Post by IanBennett »

Thanks for this.
I just would have thought it would have been done many times already using either ApplicationContext or Runspaces but is seems that this is not possible to be done in PowerShell
Do you suggest I use C# to code it to get it done?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: H0w to get Timer working with buttons

Post by jvierra »

To get what done? Any timer can easily be started with any button, but you must learn basic PowerShell before you can possibly understand how to use WinForms with PowerShell.

Here is the timer start command: $timer1.Start(). Place the code in the button click event.

If you search with your search provider for countdown timers in PowerShell you will find them by the dozens.

Part of the problem seems to be that you are giving a list of requirements and not really asking a question. Your requirements would constitute a whole list of questions, and most would have obvious answers if you simplified what you are doing and solved one problem at a time.

I will look to see if I have a countdown timer example.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: H0w to get Timer working with buttons

Post by jvierra »

Here is the only demo I have. It is old and was written more than 5 years ago but it still works.
Attachments
Demo-CountdownTimer.ps1
(4.38 KiB) Downloaded 74 times
This topic is 1 year and 8 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked