In a recent blog post Alex talked about how to create a notepad-esque application using PowerShell and the SAPIENHost object.
We're looking into building an application just like this for our service desk and I'm wondering, what are the benefits are of doing this over using a Forms project with a RichTextBox anchored and a MenuStrip?
Windows Application vs Windows Form Application
Forum rules
Do not post any licensing information in this forum.
Do not post any licensing information in this forum.
-
- Posts: 21
- Last visit: Sat Feb 24, 2024 5:20 am
- Has voted: 2 times
- Alexander Riedel
- Posts: 8479
- Last visit: Thu Mar 28, 2024 9:29 am
- Been upvoted: 37 times
Re: Windows Application vs Windows Form Application
That really depends on your use case. The blog post illustrates a sample, it is far from complete. For example the loop at the end sleeps a second between processing commands. So if you were to click really rapidly on three different topics only the last one would be executed.
In a real application you would use some type of queue for the commands. We are still building this out, but I'll give you some pro and cons.
Windows app with SAPIENHost:
Pro:
- UI and PowerShell on separate threads means UI remains responsive while Powershell processes a length statement
- Future features will allow easier thread control on PowerShell code as well as swapping out views during runtime (no, no timeline for that)
- The SAPIENHost has preset methods for file open, save as, select folder etc dialog. (Document in a soon to come blog post)
Con:
- You cannot currently debug this in the debugger. It doesn't know to create a window to show the UI and output.
- This will only run when packaged as an exe. You script will not run standalone as a PowerShell Script
Windows Forms project
Pro:
- You can debug the code in our debugger
- The script runs standalone and/or packaged
- You have control over additional application events, such as resize, close etc.
- You can add buttons and additional controls to your UI if needed
Con:
- UI and PowerShell run on the same thread. Depending on your code that may make your UI unresponsive while
longer PowerShell statements run
That's just what I can think of on top of my head. The app model is new. Which also means I am more likely to add cool new things![Very Happy :D](./images/smilies/icon_e_biggrin.gif)
In a real application you would use some type of queue for the commands. We are still building this out, but I'll give you some pro and cons.
Windows app with SAPIENHost:
Pro:
- UI and PowerShell on separate threads means UI remains responsive while Powershell processes a length statement
- Future features will allow easier thread control on PowerShell code as well as swapping out views during runtime (no, no timeline for that)
- The SAPIENHost has preset methods for file open, save as, select folder etc dialog. (Document in a soon to come blog post)
Con:
- You cannot currently debug this in the debugger. It doesn't know to create a window to show the UI and output.
- This will only run when packaged as an exe. You script will not run standalone as a PowerShell Script
Windows Forms project
Pro:
- You can debug the code in our debugger
- The script runs standalone and/or packaged
- You have control over additional application events, such as resize, close etc.
- You can add buttons and additional controls to your UI if needed
Con:
- UI and PowerShell run on the same thread. Depending on your code that may make your UI unresponsive while
longer PowerShell statements run
That's just what I can think of on top of my head. The app model is new. Which also means I am more likely to add cool new things
![Very Happy :D](./images/smilies/icon_e_biggrin.gif)
Alexander Riedel
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.