Timer to check other Timer

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 6 years and 2 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
User avatar
daniel kusnir
Posts: 75
Last visit: Tue May 23, 2023 10:50 am
Answers: 1

Timer to check other Timer

Post by daniel kusnir »

Hello

i would like to do following :

1. start 3 timers at once
2. first timer checks for network
3. 2nd renames the computer
3. 3rd one should execute code only after the 1st and 2nd timer ends

i have following code :

Code: Select all

$timerRenamePC_Tick = {
	
	if ($timerRenamePC.Tag -ne $null)
	{
		if ($timerRenamePC.Tag.state -ne 'Running')
		{
			$label_FinalComputerName.Text = Receive-Job -Name 'RenamePC' -Keep
			$script:NewDomainComputerName = $label_FinalComputerName.Text
			
			search-domaincomputer -NewDomainComputerName $NewDomainComputerName -FQDN $FQDN
			
			$timerRenamePC.Tag = $null
			$timerRenamePC.Stop
			
		}
		else
		{
		}
	}
}
inserting code :

Code: Select all

( ($timerNetworkCheck.Tag.state -ne 'Running')  -and ($timerRename.Tag.state -ne 'Running') )
does not work.

I do not want to do it via job tracker, as codeblocks there does not allow me to handle certain situations. The above is just and example, in real world i have much more timers running concurrently but need to wait for each other.

Any idea if this can be achieve via simple timers ?

thanks a lot
User avatar
daniel kusnir
Posts: 75
Last visit: Tue May 23, 2023 10:50 am
Answers: 1

Re: Timer to check other Timer

Post by daniel kusnir »

all right , i figured it out, it was very simple and stupid.

I have 3 timers, i need to get 4th to just check status of timer 1 + timer 2. Once those are both completed, initiate the
start of timer 4, and stop itself .
User avatar
mxtrinidad
Posts: 399
Last visit: Tue May 16, 2023 6:52 am

Re: Timer to check other Timer

Post by mxtrinidad »

Glad to hear! Sometimes its good to step back, look at the code again, and the magic returns.
This topic is 6 years and 2 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