proxb / PoshRSJob

Provides an alternative to PSjobs with greater performance and less overhead to run commands in the background, freeing up the console and allowing throttling on the jobs.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Documentation] WPF GUI's

burn2delete opened this issue · comments

NOTE: Just dumping my experience with WPF here for others, this project doesn't seem to have an active wiki.

  1. Showing a WPF window either via Show() or ShowDialog() MUST be done from the WPF owner thread.
  2. This means that you cannot create a window in one thread and open it from another, even with dispatcher.invoke(). This is due to the fact that if you create the window in one thread that thread will be closed once it has been created. This will cause Enumeration Errors. See #105
  3. The correct way to accomplish this is either by generating all of the windows within the main thread and invoking them separately (which can be done from separate threads however will cause ui blocking), or by showing the window the first time from the thread which created it and then later hiding the window from another thread. This will force the thread which it was created on to remain open.
  4. Using dispatcher.begininvoke() will not keep the thread open and is subject to the above issues.

For multi-window applications written in powershell (using PoshRSJob), I recommend the following:
First, creating a splash-screen in the main thread or a background thread and showing it.
Then, creating all subsequent windows (or initializing them) on the main thread. (Don't worry they have your pretty splash screen to look at while they wait.)
Third, closing the splash-screen from either the main thread or another background thread using dispatcher invoke. This gives you the option of either directly or indirectly invoking actions against the windows which you have initialized.

Yea, a wiki is probably a good idea to implement. I just created an initial page and will hopefully do more work on it in the future. Also not sure if others can contribute to the wiki or not (need to read up on that). If you happen to have code that can be released that would be a great example to show for a wiki page on working with WPF.

There should be an option in the repo settings for allowing user contributions.

Looks like it is ready for others to edit. If you want, you can give it a go and we'll see what happens.

Cool, i'll throw some code examples up once my app has stabilized a bit, probably later this week.

Great! Looking forward to it!

Just following up to see if you had a chance to add anything to the documentation.

Only what is above.

Thanks. I've taken that and created a page here: https://github.com/proxb/PoshRSJob/wiki/Building-a-WPF-Application-that-Uses-PoshRSJob

If you want to add more to it later, you can definitely do that.