Form Freezes until a command line tool completes

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 4 years and 9 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
shiroscout
Posts: 41
Last visit: Sat Jul 15, 2023 7:13 pm

Form Freezes until a command line tool completes

Post by shiroscout »

Hello friends, :geek:

I have my main form, and currently it is a PC gathering info tool :roll: ( Yet Another PC gathering tool?!), (UG! The "Hello World! of Windows Forms. ) but also have some buttons to build-in windows apps, tools, etc...

So far, it runs all the commands apparently without a problem, or really freezing or locking up.

When I run Windows "System File Checker" it runs the utility and does complete, and ( Good News Does NOT crash my GUI),
but it locks up the whole GUI until SFC completes.

Code: Select all

$picturebox58_Click={
	#TODO: Place custom script here
	
	Start-Process -FilePath "${env:Windir}\System32\SFC.EXE" -ArgumentList '/scannow' -Wait -Verb RunAs
}
I do not really understand STA mode vs Multi :mrgreen: , but I am assuming I need to do something with kicking SFC off in a new thread or something so it can be separated from my form process and do it's thing and still let a user navigate app while SFC is doing file check.

Any learning, links, direction is greatly appreciated.
Thank You,

Wayne
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Form Freezes until a command line tool completes

Post by jvierra »

All blocking code in an event will always freeze the form.

I n this case do not use "Wait" and it will not block.
User avatar
shiroscout
Posts: 41
Last visit: Sat Jul 15, 2023 7:13 pm

Re: Form Freezes until a command line tool completes

Post by shiroscout »

Thank you!

Is that it?
1 itty-bitty word is locking it up like that? :lol:
I congratulate it for doing what it was told! :D
Thank You,

Wayne
This topic is 4 years and 9 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