ProgressBar doesn't work if its called from another dll

ProgressBar doesn't work if its called from another dll

lvirone
Enthusiast Enthusiast
174 Views
1 Reply
Message 1 of 2

ProgressBar doesn't work if its called from another dll

lvirone
Enthusiast
Enthusiast

Hello everyone,

 

I have a very strange problem. My solution is made of 3 projects :

  1. The revit plugin
  2. A WPF UI project
  3. A project with process common to multiple application (like Revit, Civil3D, ...).

Each project generate a DLL, all DLLs are in the revit plugin folder. I have a progressBar in the UI project which works when called in the revit plugin project, but didn't works when called from a process in the common project (the progressbar never shown or increment).

 

In my progressBar i do this :

 

 

        private Task TaskDoEvent { get; set; }        

        protected void UpdateTaskDoEvent()
        {
            if (TaskDoEvent == null) TaskDoEvent = GetTaskUpdateEvent();
            if (TaskDoEvent.IsCompleted)
            {
                Show();
                DoEvents();
                TaskDoEvent = null;
            }
        }

        private Task GetTaskUpdateEvent()
        {
            return Task.Run(async () => { await Task.Delay(500); });
        }

        private void DoEvents()
        {
            this.Dispatcher.Invoke(() => true, DispatcherPriority.Background);
            Mouse.OverrideCursor = System.Windows.Input.Cursors.Wait;

            //Using these lines do the same result
            //System.Windows.Forms.Application.DoEvents();
            //System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor;
        }

 

 

 

"UpdateTaskDoEvent()" is called when I increment the progressBar.

 

 

public void Plus()
{
    MainProcessBar.Value++;
    UpdateTaskDoEvent();
}

 

 

 

This is the way I called the progressBar.

 

 

using (var progressBar = new MyProgressBar(100))
{
    for(int i = 0; i < 100; i++)
    {
        //Do something
        progressBar.Plus(); //The progressBar must be shown here
    }
}

 

 

 

Does somebody have an idea ? What am I doing wrong ? It's exaclty the same object, from the same dll library, but called from 2 differents locations.

 

Thanks

0 Likes
175 Views
1 Reply
Reply (1)
Message 2 of 2

jeremy_tammik
Alumni
Alumni

You say:

  

It's exactly the same object

  

However, that may not be true. It depends on how it is instantiated. Maybe you have several different object instances, and some of them are not connected to the valid Revit API context in the way you think, and therefore have no access to the Revit API, and therefore cannot update your progress bar... it depends on your architecture. Maybe it will help clarify things if you ensure that your object is a singleton that can only be instantiated once:

  

https://duckduckgo.com/?q=c%23+singleton

   

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes