0

I created a Winforms dashboard for my team using Powershell and I've put alot of features into the the thing (a tab that does webscraping, another tab that uses an API, another tab that sends emails, etc) and I just realized that I am unable to run different features simultaneously.

Some of the functions take awhile to actually run (like 1 minute or so) and while one feature is running, the entire winforms application is frozen until it finishes, before users are able to move onto another feature.

Is there a way around this? I know I can't be the only one who's ran into this issue. I want users to be able to run different dashboard functions simultaneously.

All of my code is currently in 1 .PS1 file which has over 1500 lines of code. I was thinking of maybe segmenting it off into different scripts and then having my dashboard call those other scripts once a function is invoked? Although I'm not so sure that would do what I'm looking to accomplish.

Any suggestions would be much appreciated.

Michael
  • 53
  • 4
  • 1
    This is for WPF, but the principle is similar for WinForms: https://stackoverflow.com/questions/21419229/c-sharp-threading-async-running-a-task-in-the-background-while-ui-is-interactab. – wohlstad Sep 26 '22 at 06:17
  • 1
    You need to setup different threads, see: [PowerShell: Job Event Action with Form not executed](https://stackoverflow.com/a/40808521/1701026) – iRon Sep 26 '22 at 06:23
  • Ah thank you so much guys, this really puts me in the right direction – Michael Sep 26 '22 at 06:29
  • 1
    I have 2 examples using runspace in my gists that might be useful too, https://gist.github.com/santysq/139d6e19d4b14a9c6be4737c72eb79e4 and https://gist.github.com/santysq/edba1d1a8b63ad3131746702d4b371a9 – Santiago Squarzon Sep 26 '22 at 13:12

0 Answers0