script stays in taskman

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
User avatar
mqh777
Posts: 237
Joined: Tue Feb 25, 2014 1:01 pm

script stays in taskman

Post by mqh777 » Fri Feb 22, 2019 8:46 am

I have a form that is compiled into an .EXE. It displays a message saying your system will reboot in 5 min, please close your apps. I've run this on a few different machines and on 2 of them after the reboot this compiled .exe was STILL showing as a Process in TaskMan and the machine kept rebooting ever 5 min. Why? what in this code would cause that behavior?

Code: Select all


#  This will create a countdown timer on the form
$FormEvent_Load={
	$labelTime.Text = "{0:D2}" -f $TotalTime
}

# Set countdown to 3 minutes or 180 seconds
$TotalTime = 300

$script:StartTime = (Get-Date).AddSeconds($TotalTime)
$timerUpdate.Start()


$timerUpdate_Tick={
	#Use Get-Date for Time Accuracy
	[TimeSpan]$span = $script:StartTime - (Get-Date)
	#Update the display
	$formRebootSystem.Text = $labelTime.Text = "{0:N0}" -f $span.TotalSeconds
	if($span.TotalSeconds -le 0)
	{
		# Once 300 seconds have gone by reboot the system	
		Restart-Computer localhost -Force
	}
}

$labelTime_Click={
	#TODO: Place custom script here
	
}

$FormEvent_Load={
	#TODO: Place custom script here
	
}

$labelSecondsRemainingUnti_Click={
	#TODO: Place custom script here
	
}

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

Re: script stays in taskman

Post by jvierra » Fri Feb 22, 2019 1:37 pm

Windows 10 remembers an loads processes that were running when the system shut down. They are reloaded when th system restarts. Place the timer.Start command outside of an event will likely cause this behavior.

Placing the timer.start() call in the "Shown" event of the form may prevent this.

Locked