Progress Dialog not always updating

Progress Dialog not always updating

Kevin.Bell
Advisor Advisor
1,286 Views
7 Replies
Message 1 of 8

Progress Dialog not always updating

Kevin.Bell
Advisor
Advisor

Hi,

 

I’ve created a C# routine which processed Areas and creates plans from them – they all works really well and I’m happy with the result.

 

There is one minor issue, which is, when the routine runs on a big model, it takes a while to complete and the user assumes that Revit has crashed.

 

I added a progress dialog in the form of a Modeless dialog which has two progress counters on it. As the routine executes it updates the progress counters and informs the users.

 

I found that I had to call dialog.Refresh() every time I updated the counter otherwise the dialog would not update.

 

So this all works fine on the machine I wrote the code on, but I’ve found when I run it on another machine the progress dialog doesn’t update. Sometimes it does update one of the progress counters, other times the whole dialog doesn’t refresh and it displays as white blocks.

 

I’m struggling to understand why it works fine on one machine and not on another.

 

I’d appreciate some tips on getting this to work.

 

0 Likes
Accepted solutions (1)
1,287 Views
7 Replies
Replies (7)
Message 2 of 8

aricke59
Enthusiast
Enthusiast

Try throwing in a 

 

System.Windows.Forms.Application.DoEvents()

 

e.g.

pdialog.pBar.PerformStep()
pdialog.label.Text = "Processing: " & f.Name
System.Windows.Forms.Application.DoEvents()

0 Likes
Message 3 of 8

Kevin.Bell
Advisor
Advisor

arike - that's for your response, I tried it, but it made no difference

 

Strangely, the dialog closed and control was returned to Revit and then a minute later my routine reported that it has completed...

 

Its also strange that dialog.Refresh() doesn't actually update the dialog...

0 Likes
Message 4 of 8

Kevin.Bell
Advisor
Advisor

Perhaps the solution should be to use a modal dialog box rather than a modeless one...

 

At the moment I have a c# class which call the a modal dialog which collects user input, on close the class then does the tasks and displays a modeless dialog to give progress (which doesn't work).

 

Perhaps if I moved all the code which does the processing tasks into the OK button function of the dialog, that way the routine would execute with a modal dialog which could also display progress.

 

I'm fairly new to c# as you can probably tell, I'm not too sure whether this would work or not...

 

(I hope the above makes sense!)

0 Likes
Message 5 of 8

DavidWoodCT
Enthusiast
Enthusiast
Accepted solution

Hi Kevin,

 

I'm not sure that you need to have the progress dialog as modeless? You're not expecting the user to do anything with Revit while your code runs, and your code is happy running behind a modal dialog? So why not just launch the modal progress box and call your processing from there? Then you can do the progress updates easily, deal with a 'cancel' button, etc.

 

I'm assuming you're using simple Windows Forms, and not complex MVVC WPF stuff...

 

The modeless option is fine, but it's a trickier thing to get right IMHO.

 

Kind regards,

 

David

0 Likes
Message 6 of 8

Kevin.Bell
Advisor
Advisor

Hi David,

 

You right, the form is a simple Windows Form and I'm not doing anything complex that requires input.

 

I'm unsure how to cell the code from the dialog -I tried to do that once before but had issues the code not knowing the variables that I had set previously...

 

I guess this is because I'm not passing the variables from the code to the dialog and back again correctly.

 

I'll try to do it again...

 

Thanks.

 

 

Message 7 of 8

DavidWoodCT
Enthusiast
Enthusiast

Hi Kevin,

 

Yes, you have to look after the Scope of the variables.

 

I guess if I was approaching this, I'd split the 'processing code' into a separate class, which I'd instantiate from the progress dialog. Then I'd know which data I had to pass at each step: callingClass -> getUserDataDialog -> progressDialog -> processingClass. But there are plenty of other ways you could do it.

 

Kind regards

 

David

0 Likes
Message 8 of 8

Kevin.Bell
Advisor
Advisor

David,

 

Thanks - your suggestion worked well.

 

Cheers,

Kevin.

0 Likes