CAB and Offline Application Block (OAB) together

Topics: CAB & Smart Client Software Factory
Nov 3, 2005 at 2:48 PM
originally posted by: tbag

I have successfully implemented the CAB and OAB together but I am having a small issue. I used the CAB SmartPart QuickStart as the pattern for creating my SmartPart application. This QuickStart utilizes a class called SmartPartApplication.cs to provide the Main() function to serve as an entry point to the application. I modified the code in the Main method to implement the OAB functionality when my application starts.

public static void Main()
MainForm mainForm = new MainForm();
connectionManagementController = new ConnectionController(mainForm);
connectionManagementController = null;
if (connectionManagementController != null)
new SmartPartApplication().Run();

I used the OAB Connection Management QuickStart as the pattern to implement the OAB. The application properly detects the connection state. I created two menu items in my MainForm to toggle the connection state from Online to Offline, both work properly.

Here is my issue. When the application is first loaded the SmartPartApplication().Run() code starts my application and the ConnectionManagerConnectionStateChangedEvent event handler properly detects the connection state.

The ConnectionController class UpdateState method then executes to update the connection status in the MainForm. Then the MainForm UpdateState method executes to set the enabled status of my menu items that toggle the connection state and set the status bar label.

After the MainForm UpdateStatus method executes the constructor for the MainForm class fires again and the InitializeComponent method is called. When the InitializeComponent method is called again the value for my status bar label is set back to its default Value.

Once the application is loaded, clicking the menu items I have created to toggle connection state properly toggle the enabled state of the menu items and update the status bar label.

The event handlers for the menu items mentioned above call the UpdateState method of the MainForm.

private void goOnlineToolStripMenuItem_Click(object sender, EventArgs e)

private void goOfflineToolStripMenuItem_Click(object sender, EventArgs e)

These event handlers work properly because the MainForm constructor is not called again when they execute and the InitializeComponent method is not called.

I am trying to determine the correct place to implement the code to make the OAB functionality work inside my application without calling the constructor of the MainForm twice when the application is loaded. Does anyone know why this constructor is being called twice when the application is initially loaded? How can I work around this?
Jul 28, 2006 at 8:57 AM
originally posted by: JKraft4PIT

I have aslready done this. I did it quite differnetly by creating a instance of the ConnectionMamager in the ShellsWorkItem (aka RootWorkItem).

I then handle the connection changed event and Use a UIExtension point to update the state on the status Menu.

I am not sure how you are doing it exactyl, or even where you call the Application.Run.

If you want some clarity I can show some code.

Things you should know before I put up my code.
How to use the EventBroker and UIExtensions.