I've created a Form with a few buttons on that interacts with (a remote) Microsoft Identity Integration Server. It simply tells various MIIS Management Agents to perform an import or export to the metaverse. No value is returned by the form but Out-Gridview and a TextBox control on the form are used to report on results and errors.
The MIIS interaction is by calling a method on an WMI object. Some of these methods can take a few minutes to finish. I update the status bar of the form before and after and show/hide a big "Please wait" message (a label control) too. During the time the method is executing, the form cannot even be dragged around the screen. I was hoping I could make it less dead during this time. I know it's only cosmetic, but I like a challenge!
My idea for a solution was something like this:
$maScriptBlock = { Param($adMA) $adMA.Execute("Import") }
$maJob = Start-Job -ScriptBlock $maScriptBlock -ArgumentList $activeDirectoryMA
# Then do something else until job complete - eg dynamically changing status bar message.
# The job is then received and removed.
For reference, if you're wondering:
$activeDirectoryMA = Get-WmiObject -ComputerName REMOVED -Namespace "root\MicrosoftIdentityIntegrationServer" -Class MIIS_ManagementAgent -Filter "Name='Active Directory MA'"
Unfortunately the form still becomes frozen in place and the script goes no further while the method is called. I thought having it run as a job would free the script up to do other things.
Then I wondered if it was to do with STA vs MTA (I'm not a developer and don't really know much about this at all). My form doesn't return a value so I thought I'd try launching PowerShell ISE with -MTA to test it. When I tried that, showing the hidden "Please Wait" label did not work properly and the Form said "not responding", though when left alone, the script did finish doing what it should have been and the form came back to life.
Is there anything I can do to work around this apart from learn C# and write a real app?!
Thanks!