<?xml version="1.0" encoding="UTF-8"?>
<code>
  <code>##code
public static class BusyIndicator
{
private static readonly AsyncCallback   nullCallback    = delegate { };
        private static readonly object[]        emptyArray      = new object[] { };

        public static void ShowWhile(Control control, ThreadStart method)
        {
            if (method == null)
                throw new ArgumentException("Missing method definition", "method");

            if (control == null)
            {
                method.BeginInvoke(nullCallback, emptyArray);
                return;
            }

            control.Cursor = Cursors.WaitCursor;
            MethodInvoker callback = delegate   { control.Cursor = Cursors.Default; };
            AsyncCallback invoke   = delegate   { control.Invoke(callback); };
            method.BeginInvoke(invoke, emptyArray);           
        }
    }

##sample usage
BusyIndicator.ShowWhile(this, delegate
{
    // Do stuff
});</code>
  <comment>Show a BusyIndicator during long-tasks execution.</comment>
  <created-at type="datetime">2007-09-26T23:40:49+00:00</created-at>
  <id type="integer">18</id>
  <language>C#</language>
  <permalink>net-busyindicator</permalink>
  <refactors-count type="integer">9</refactors-count>
  <title>.NET BusyIndicator</title>
  <trackback-url></trackback-url>
  <updated-at type="datetime">2008-09-23T20:29:19+00:00</updated-at>
  <user-id type="integer">10</user-id>
  <refactors type="array">
    <refactor>
      <code></code>
      <code-id type="integer">18</code-id>
      <comment>Seems ok to me. I doubt if refactoring could make it more readable.

Of course, unless you have many of such busy indicators, and of various kinds.

If it's the only busy indicators, then its very fine </comment>
      <created-at type="datetime">2007-09-27T00:34:15+00:00</created-at>
      <id type="integer">44</id>
      <language>C#</language>
      <rating type="integer">4</rating>
      <ratings-count type="integer">2</ratings-count>
      <title>On .NET BusyIndicator</title>
      <user-id type="integer" nil="true"></user-id>
      <user-name>Darius Damalakas</user-name>
      <user-website></user-website>
    </refactor>
    <refactor>
      <code>##code provided by &lt;a href="http://blogs.ugidotnet.org/Crad/Default.aspx"&gt;Marco De Sanctis&lt;/a&gt; 
public class WaitCursor: IDisposable
{
public WaitCursor()
{
Cursor.Current = Cursors.WaitCursor;
}
public void Dispose()
{
Cursor.Current = Cursors.Default;
}
}

##usage
using (new WaitCursor())
{
// some code here
}
</code>
      <code-id type="integer">18</code-id>
      <comment>I've tested the code and this indicator is something like "Control-specific": this means that the BusyIndicator is showed only when the mouse is under the specific control, and not globally showed (better solutions exists for a global busy indicator using Cursor.Current).
This means that you could use (i think) more than one of this snippets at the same time, using different components as "host".
Now a better solution for a global wait cursor.</comment>
      <created-at type="datetime">2007-09-27T00:41:46+00:00</created-at>
      <id type="integer">45</id>
      <language>C#</language>
      <rating type="integer">0</rating>
      <ratings-count type="integer">0</ratings-count>
      <title>On .NET BusyIndicator</title>
      <user-id type="integer">10</user-id>
      <user-name>D_Guidi</user-name>
      <user-website>http://code.google.com/p/nettopologysuite/</user-website>
    </refactor>
    <refactor>
      <code></code>
      <code-id type="integer">18</code-id>
      <comment>One problem with the original code is that after the method is invoked, it resets controls cursor to Cursors.Default, which might be not what was before.

Imagine, that the cursor was a magnify glass, and after the call it gets reset to Cursor.Default. IMHO, that's not what we want. We want the code to reset the cursor to previous state.

No code examples, since that's trivial to implement.</comment>
      <created-at type="datetime">2007-09-27T02:12:45+00:00</created-at>
      <id type="integer">46</id>
      <language>C#</language>
      <rating type="integer">5</rating>
      <ratings-count type="integer">1</ratings-count>
      <title>On .NET BusyIndicator</title>
      <user-id type="integer" nil="true"></user-id>
      <user-name>Darius Damalakas</user-name>
      <user-website></user-website>
    </refactor>
    <refactor>
      <code></code>
      <code-id type="integer">18</code-id>
      <comment>I agree with you, Darius.
Simply, i need to store cursor's status in a field before the invoke, and use this field to restore the correct status in the callback.
Thanks for the suggest ;)

P.S: this service is so cool :)</comment>
      <created-at type="datetime">2007-09-28T00:10:43+00:00</created-at>
      <id type="integer">65</id>
      <language>C#</language>
      <rating type="integer">0</rating>
      <ratings-count type="integer">0</ratings-count>
      <title>On .NET BusyIndicator</title>
      <user-id type="integer">10</user-id>
      <user-name>D_Guidi</user-name>
      <user-website>http://code.google.com/p/nettopologysuite/</user-website>
    </refactor>
    <refactor>
      <code>public class WaitCursor: IDisposable
{
  public WaitCursor(Form form)
  {
    form.UseWaitCursor = true
  }
  
  public void Dispose()
  {
    form.UseWaitCursor = false
  }
}
</code>
      <code-id type="integer">18</code-id>
      <comment>Under .NET 2.0 and onwards, you can also use the UseWaitCursor property. This overrides other cursor settings without changing them, so once you set it to false again you automatically get your old cursor back.</comment>
      <created-at type="datetime">2007-09-28T01:30:36+00:00</created-at>
      <id type="integer">76</id>
      <language>C#</language>
      <rating type="integer">5</rating>
      <ratings-count type="integer">1</ratings-count>
      <title>On .NET BusyIndicator</title>
      <user-id type="integer" nil="true"></user-id>
      <user-name>Avish</user-name>
      <user-website></user-website>
    </refactor>
    <refactor>
      <code>public class WaitCursor: IDisposable
{
  public WaitCursor(Control control)
  {
    control.UseWaitCursor = true
  }
  
  public void Dispose()
  {
    control.UseWaitCursor = false
  }
}</code>
      <code-id type="integer">18</code-id>
      <comment>Cool :)
A suggest, You could (i think, looking at msdn: http://tinyurl.com/26rqaq) use a Control instead of a Form as a parameter... right?</comment>
      <created-at type="datetime">2007-09-28T03:41:53+00:00</created-at>
      <id type="integer">89</id>
      <language>C#</language>
      <rating type="integer">0</rating>
      <ratings-count type="integer">0</ratings-count>
      <title>On .NET BusyIndicator</title>
      <user-id type="integer">10</user-id>
      <user-name>D_Guidi</user-name>
      <user-website>http://code.google.com/p/nettopologysuite/</user-website>
    </refactor>
    <refactor>
      <code></code>
      <code-id type="integer">18</code-id>
      <comment>control.FindParent will find the form the control is on.  Then you can set the cursor for the entire form.</comment>
      <created-at type="datetime">2007-10-01T10:37:18+00:00</created-at>
      <id type="integer">155</id>
      <language>C#</language>
      <rating type="integer">0</rating>
      <ratings-count type="integer">0</ratings-count>
      <title>On .NET BusyIndicator</title>
      <user-id type="integer" nil="true"></user-id>
      <user-name>Nathan</user-name>
      <user-website></user-website>
    </refactor>
    <refactor>
      <code>public interface IView {
    void ShowWaitState();
    void ShowReadyState();
}

public class Presenter {
    private IView view;
    public Presenter(IView view) {
        this.view = view;
    }

    public void DoSomething() {
        view.ShowWaitState();
        // ... 
        view.ShowReadyState();
    }
}</code>
      <code-id type="integer">18</code-id>
      <comment>If I were using this in an MVP pattern I would try to leave the implementation of the wait state up to the view. This way I can re-use the code in an ajax control (set some visual wait indicator) or a winforms application (set the wait cursor).</comment>
      <created-at type="datetime">2007-10-23T13:38:54+00:00</created-at>
      <id type="integer">512</id>
      <language>C#</language>
      <rating type="integer">0</rating>
      <ratings-count type="integer">0</ratings-count>
      <title>On .NET BusyIndicator</title>
      <user-id type="integer" nil="true"></user-id>
      <user-name>JH</user-name>
      <user-website></user-website>
    </refactor>
    <refactor>
      <code></code>
      <code-id type="integer">18</code-id>
      <comment>Did you used to work at Geac?</comment>
      <created-at type="datetime">2008-09-23T20:29:18+00:00</created-at>
      <id type="integer">29598</id>
      <language>C#</language>
      <rating type="integer">0</rating>
      <ratings-count type="integer">0</ratings-count>
      <title>On .NET BusyIndicator</title>
      <user-id type="integer" nil="true"></user-id>
      <user-name>Mike</user-name>
      <user-website></user-website>
    </refactor>
  </refactors>
</code>
