The Kinetic Jump site navigation header requires JavaScript to be enabled and the latest version of the Macromedia Flash Player. If you are you using a browser with JavaScript disabled please enable it now. Otherwise, please update your version of the free Flash Player by downloading here.

Welcome Guest Search | Active Topics | Log In | Register

Using AppLife Update in WPF applications Options
brianh
#1 Posted : Friday, July 11, 2008 11:38:22 AM
Rank: Administration
Groups: Member, Administration

Joined: 5/24/2007
Posts: 362
Location: Minnesota

Using AppLife Update in WPF applications is pretty straightforward as the Update Controller is not a visual control. No WindowsFormsHost interop control required.  You just instantiate an Update Controller, set its properties and call its methods.

 

There are a few things to keep in mind when planning an AppLife Update integration into WPF.

 

1.  To allow AppLife Update to gracefully shutdown multple instances of your application and provide the ShutdownRequested event, an instance of the AppLife Update controller needs to be instantiated.  When you add the control onto a winforms form designer, this is taken care of for you.  But if you create the control in code, you will need to instantiate your update controller in an application scope if you want to take advantage of the built-in IPC betwen your application instances.  A member variable of your main WPF dialog is a good place to create a controller.

 

2.  The Update Controller is Disposable and needs to be disposed.  WPF will not dispose the controller for you as the WinForms Container does.  You will need to dispose your controller before it goes out of scope.

 

3.  Although the Update Controller is not a visual control, the built-in forms that you can utilize are Windows Forms based.  If you want to use the UpdateInteractive method or any of the individual ShowForms methods, and have the forms appear above your application and centered, then you will want to set an owner on the Update Controller.  Here is a simple class that you can use to assign your WPF Window as the owner.

 

private class WindowWrapper : System.Windows.Forms.IWin32Window {

       private System.Windows.Interop.WindowInteropHelper mHelper;

 

       public WindowWrapper(Window window) {

              if(window != null) {

                     mHelper = new System.Windows.Interop.WindowInteropHelper(window);

              }

       }

 

       public IntPtr Handle {

              get {

                     if(mHelper == null) {

                           return IntPtr.Zero;

                     } else {

                           return mHelper.Handle;

                     }

              }

       }

}

 

Then just call updateController1.UpdateInteractive(new WindowWrapper(this));

 

The built-in UI will behave appropriately.

 

The attached cs file provides a simple example of using AppLife Update in a WPF application.  Keep in mind that a complete WPF based user interface can be created to replace the call to UpdateInteractive, just as you can do in winforms.  Review the API Reference for all of the methods, events and properties of the Update Controller.

File Attachment(s):
Window1.xaml.cs (2kb) downloaded 53 time(s).
Brian Haas
Kinetic Jump Software
Users browsing this topic
Guest
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.