Examples of BusyIndicator

Oct 7, 2011 at 1:47 PM
Edited Oct 7, 2011 at 1:51 PM

Hello,

Anyone knows where to find examples of BusyIndicator with the WPF Toolkit?

I have this problem, I create the BusyIndicator in a WPF but when the screen loads the system show the following message: Set connectionId threw a exception. Line number 5 and lite position 167

But when I comment the busyIndicator the  I don't have this problem.. What I can do?

The window line is this: xmlns:extToolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit/extended"

And the BusyIndicator is this: <extToolkit:BusyIndicator Height="300" HorizontalAlignment="Center" Margin="0" Name="busyIndicator1" VerticalAlignment="Center" Width="500" BusyContent="Loading..." />.

And I want to show this busyIndicator when the system call a function in other times the busyindicator will be invisible.

Thanks for the attencion.

André Ishihara

Oct 7, 2011 at 1:51 PM

How are you using the BusyIndicator?  Are your long running processes on a background thread?  If they are, are you trying to access the BusyIndicator on a different thread?  Read the inner exception of your exception.  This may provide more information.  Please share your code.

Oct 7, 2011 at 5:47 PM

First, this problem is happening when I load the screen. The BusyIndicator is not even used yet. I'm trying to open first, but is not working... I have no idea where to search this error. The Debug point to the window tag in the WPF. But I have no idea where to look to resolve this problem.

Oct 7, 2011 at 5:51 PM

This is not enough information for me to debug.  This is not related to the BusyIndicator.  You have a different problem.  What is the stack trace of the runtime error?

Oct 7, 2011 at 6:24 PM

I don't know what to do, so you know any examples, to how to use the busy indicator? At this moment I just want to work with this item. But when I try to use the screen doesn't work and throw an exception. But I don't know what to do, so I want a example to compare.

Oct 7, 2011 at 6:26 PM

Give me the stack trace of the exception.  I will help you find the root cause.  Is it a runtime exception or design time?  I will also write up a blog post on how to use the BusyIndicator.

Oct 7, 2011 at 7:18 PM

stack trace:

   at System.Windows.Markup.XamlReader.RewrapException(Exception e, IXamlLineInfo lineInfo, Uri baseUri)
   at System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri)
   at System.Windows.Markup.WpfXamlLoader.LoadBaml(XamlReader xamlReader, Boolean skipJournaledProperties, Object rootObject, XamlAccessLevel accessLevel, Uri baseUri)
   at System.Windows.Markup.XamlReader.LoadBaml(Stream stream, ParserContext parserContext, Object parent, Boolean closeStream)
   at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)
   at SIN.WPF.Principal.InitializeComponent() in c:\Projects\SIN\AL\SIN\WPF\Principal.xaml:line 1
   at SIN.WPF.Principal..ctor() in C:\Projects\SIN\AL\SIN\WPF\Principal.xaml.cs:line 54

SIN: The System name.

Principal: The screen where the BusyIndicator will be utilized.

The error is on runtime but points to the tag<window> in the design.

Oct 7, 2011 at 7:44 PM

Can you post your XAML and Code-behind?

Oct 7, 2011 at 10:12 PM

Here is the post on using the busy indicator:

http://elegantcode.com/2011/10/07/extended-wpf-toolkitusing-the-busyindicator/

Oct 10, 2011 at 5:52 PM

One Problem solved. I created your example in a new project. I observe something. The project get the 3.5 dll. So I tried this: I removed the 4.0 dll and changed to the 3.5 dll(both of them). And worked. But now I have another problem, but this only shows when I'm trying to look at the design appear the following error: "Ambiguous type reference. A type named 'VisualStateManager' occurs in at least two namespaces, 'System.Windows' and 'System.Windows'. Consider adjusting the assembly XmlnsDefinition attributes.". But the system in runtime works. So I cannot understand why the error... Sorry for the incovenience. And thanks for the help.

Oct 10, 2011 at 5:57 PM

The reason you are getting this is because you have a .NET 4 application but you are including the .NET 3.5 WPF Toolkit which also has the VisualStateManger in it in the same namespace.

If you have created a .NET 4 application you only need to add a reference to the Extended WPF Toolkit 1.5 .NET 4.0 DLL: http://wpftoolkit.codeplex.com/releases/view/71499#DownloadId=268513

Download it, right clikc and select properties ot unblock it.  Then add it to your project.

Oct 10, 2011 at 6:52 PM

Thank you, it works. One more question. I can do something like this?

busyIndicator1.IsBusy = true

//Process

busyIndicator1.IsBusy = false

Because the busyIndicator screen is not showing when I do this.

I don't if this helps but, in the design I make something like this:

<extToolkit:BusyIndicator Name="BusyIndicator1" VerticalAlignment="Stretch" IsBusy="false" Width="Auto" Height="Auto">

 <Grid>

//Layout of screen not using references or background here. These are in <Windows.References> and <Windows.Background>

</Grid>

</extToolkit:BusyIndicator>

Is something wrong in this?

Oct 10, 2011 at 6:55 PM

You need to read the article I provided.  It explains what is happening.  You need to place your process on a background thread.

Oct 10, 2011 at 7:25 PM

Even if I just want to show the BusyIndicator? I don't need to show how much time it's takes, I only want to indicate the process is working. But if it's not possible, I will try to do this way.

Oct 10, 2011 at 7:26 PM

Correct.  Your process will block the UI thread.

Oct 10, 2011 at 8:04 PM

Almost there,

I want to know if it's possible to show the busyIndicator before the process starts.

Oct 10, 2011 at 8:05 PM

That's what you need to do.  IsBusy = true, then start background process, when background process ends IsBusy = false.

Oct 11, 2011 at 1:04 PM

Is something like this?

BusyIndicator1.IsBusy = true

                BackgroundWorker worker = new BackgroundWorker();
                worker.DoWork += (object s, DoWorkEventArgs args) =>
                {
                    for (int i = 0; i < 100; i++)
                    {
                        System.Threading.Thread.Sleep(50);
                    }
                };
                worker.RunWorkerCompleted += (s, args) =>
                {
                    BusyIndicator1.IsBusy = false;
                };
                worker.RunWorkerAsync();

                //Process

BusyIndicator1.IsBusy = False

Oct 11, 2011 at 1:33 PM

Almost:

                BackgroundWorker worker = new BackgroundWorker();
                worker.DoWork += (object s, DoWorkEventArgs args) =>
                {
                    for (int i = 0; i < 100; i++)
                    {
                        System.Threading.Thread.Sleep(50);
                    }
                };
                worker.RunWorkerCompleted += (s, args) =>
                {
                    BusyIndicator1.IsBusy = false;
                };
                BusyIndicator1.IsBusy = true
                worker.RunWorkerAsync();
Oct 11, 2011 at 2:38 PM
Edited Oct 11, 2011 at 2:38 PM
brianlagunas wrote:

Almost:

                BackgroundWorker worker = new BackgroundWorker();
                worker.DoWork += (object s, DoWorkEventArgs args) =>
                {
                    for (int i = 0; i < 100; i++)
                    {
                        System.Threading.Thread.Sleep(50);
                    }
                };
                worker.RunWorkerCompleted += (s, args) =>
                {
                    BusyIndicator1.IsBusy = false;
                };
                BusyIndicator1.IsBusy = true
                worker.RunWorkerAsync();

The problem with this method is: No matter where I put the process the BusyIndicator always shows after the process(I really tried). Any Ideas to call the BusyIndicator before the process?

Oct 11, 2011 at 2:41 PM

That code snippet is showing the BusyIndicator before the process.  You need to put the process in the DoWork event handler.  So where you see "for (i = 0; i < 100; i++) ..." Remove that and put your process there in its place.

Oct 11, 2011 at 2:42 PM
                BackgroundWorker worker = new BackgroundWorker();
                worker.DoWork += (object s, DoWorkEventArgs args) =>
                {
                    //PROCESS GOES HERE
                };
                worker.RunWorkerCompleted += (s, args) =>
                {
                    BusyIndicator1.IsBusy = false;
                };
                BusyIndicator1.IsBusy = true
                worker.RunWorkerAsync();

Oct 11, 2011 at 2:44 PM

This post will be helpful for you to read to learn more about multi-threading:

http://elegantcode.com/2009/07/03/wpf-multithreading-using-the-backgroundworker-and-reporting-the-progress-to-the-ui/

Oct 14, 2011 at 7:26 PM
brianlagunas wrote:
                BackgroundWorker worker = new BackgroundWorker();
                worker.DoWork += (object s, DoWorkEventArgs args) =>
                {
                    //PROCESS GOES HERE
                };
                worker.RunWorkerCompleted += (s, args) =>
                {
                    BusyIndicator1.IsBusy = false;
                };
                BusyIndicator1.IsBusy = true
                worker.RunWorkerAsync();

Thank you very much. This is is the solution of my problem. Thank you for the help and pacience.

Oct 14, 2011 at 7:28 PM

No problem. I'm here to help. You can thank me by rating the project with your impressions.

Oct 24, 2011 at 7:01 PM

A question. I have this situation: Sometimes when I use the busyIndicator, it shows but sometimes doesn't. I'm doing something wrong? And is in the same screen. Sometimes when I do some action the BusyIndicator appears but sometimes when I do the same action the BusyInidicator doesn't show but the controls stay disabled. I want to show the BusyInidicator always when possible.

Oct 24, 2011 at 7:47 PM

Your issue is quite broad and there isn't enough information provided to accurately provide any type of assistance.  The only thing I can think of, assuming everything is implemented cxorrectly, is that the second time you perform the action it occurs so fast that the BusyIndicator doesn't have time to show.

Oct 25, 2011 at 1:09 PM

I make some adjustments in the program and now it's good. Is probably the BusyIndicator doesn't have time to show. Thank you again for the help.