Reply
Solved! Go to solution

Retrieve Application.StatusBar text in "real time" when Solid Edge is busy

[ Edited ]

Hi all,

 

I'm trying to retrieve the Application.StatusBar text and display it in my own window. The purpose is to display the loading information in my window (e.g. "Searching linked documents..."). I ran into the following problems:

 

1) I can't seem to find an event which occurs when the StatusBar text has changed

2) When Solid Edge is busy (i.e. loading a big assembly), I can't retrieve the StatusBar text. 

 

Due to 1), I did the following:

 

StatusUpdateArgs args = new StatusUpdateArgs();

var thread = new System.Threading.Thread(() =>
{
while (app != null)
{
System.Threading.Thread.Sleep(10);
args.StatusText = app.StatusBar;
if (StatusUpdated != null)
{
StatusUpdated(this, args);
}
}
});

 

The event StatusUpdated occurs every 10 milliseconds and sends the text to the GUI. Now I run into problem 2) where the text in the GUI only gets updated when Solid Edge is on idle (I guess). My guess would be that Solid Edge is "too busy" during the loading process of a file and doesn't "feed" the COM Server with the information I need. But maybe I'm doing something wrong?

 

EDIT: I just tried to refresh the Spy For Solid Edge during the loading process of a fairly big assembly. Looks like it has the same problem as my app, refresh is impossible...

 

Regards,

Jonas

2 REPLIES
Solution
Solution
Accepted by topic author freijon
‎08-26-2015 04:32 AM

Re: Retrieve Application.StatusBar text in "real time" when Solid Edge is busy

Since there is not an event to tell you when the status bar is updated, you are relegated to "polling" which is almost always a bad idea. Necessary sometimes, but should always be a last resort if absolutely necessary.

 

One bit of confusion that I see, if you look at the Application.StatusBar property, it is actually showing you the text of the "PromptBar". If you try setting Application.StatusBarVisible = false, it does not hide the "PromptBar" but rather hides the bar below it. I'm curious if you're after the "PromptBar" text or the text that is shown in the bar below it.

 

Of course I had to write some code to test it myself so here is what I tried. It is a console application that uses the SolidEdge.Community NuGet Package.

 

using SolidEdgeCommunity;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;

namespace MonitorStatusBar
{
    class Program
    {
        [STAThread]
        static void Main(string[] args)
        {
            // Register the OLE message filter to avoid RPC_E_CALL_REJECTED.
            OleMessageFilter.Register();

            // Connect to a running instance of Solid Edge.
            var application = SolidEdgeUtils.Connect(false);

            foreach (var i in Enumerable.Range(0, 10000))
            {
                // Sleep 10 milliseconds.
                System.Threading.Thread.Sleep(10);

                // Start the stopwatch.
                Stopwatch stopwatch = new Stopwatch();
                stopwatch.Start();

                // Access the property.
                var statusBar = application.StatusBar;

                // Stop the stopwatch.
                stopwatch.Stop();

                // Trim the string to 40 characters.
                statusBar = new string(statusBar.Take(40).ToArray());
                Console.WriteLine("{0} ({1}) - {2}", i, stopwatch.Elapsed, statusBar);

                // Check to see if application.StatusBar took more than 1 second.
                if (stopwatch.Elapsed.Seconds > 0)
                {
                    System.Diagnostics.Debugger.Break();
                }

            }

            OleMessageFilter.Unregister();
        }
    }
}

 What I see in my test of loading a large assembly, I will hit the Debugger.Break() statement if the operation took longer than 1 second. So you are correct in that when Solid Edge is busy, it won't respond to your request. Not sure that any of this helps other than to confirm what you're seeing.

Jason Newell
Applications Architect
www.jasonnewell.net

Re: Retrieve Application.StatusBar text in "real time" when Solid Edge is busy

Thanks for trying this. I guess I have to live with and search a workaround. Regarding your question: I was in fact after the PromptBar text which contains the text, not the bar below that gets hidden.