【问题标题】:BusyIndicator never stopsBusyIndi​​cator 永远不会停止
【发布时间】:2013-06-17 10:49:06
【问题描述】:

我要加载大数据,所以我决定在加载时使用busyIndicator。 问题是,我显示加载数据文本,但它永远不会停止。

  public mainWindow()
        {
            InitializeComponent();
            rbi.IsBusy = true;
            Task.Factory.StartNew(getData);
        }


void getData()
        {

//method which loading data and inserting them into dataGrid
            Metoda();
            this.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Send,
                                       (Action)delegate
                                       {
                                           rbi.IsBusy = false;
                                       });

        }

BusyIndicator 包含网格,所以看起来像

<BusyIndicator>
<Grid>
<GridView>
....

@编辑: 方法“方法”:

         void Metoda()
            {
            using (SqlConnection conn = new SqlConnection(cString.c_String))
            {
                conn.Open();
                using (SqlCommand cmd = new SqlCommand("...", conn))
                {
//when entering there, it break and doesnt continue.
                    using (SqlDataReader rdr = cmd.ExecuteReader())
                    {
                        while (rdr.Read())
                        {
                            needUpdate = rdr.GetBoolean(rdr.GetOrdinal("needUpdate"));
                        }
                    }
                }
            }
            if(needUpdate)
            {
    //loading data into static list of 'Product' type (read from DB using dataReader and add into static list - prodList)
                 FastSellSearchClass.GetProducts(wID);
            }
            GetProducts("", -1);
            }

            void GetProducts()
            {
            (...)
            //set itemssource = static list from previous method
            gridView.ItemsSource = FastSellSearchClass.prodList;
            }

@EDIT2: XAML 文件:

    <Grid>
            <my:BusyIndicator Name="rbi" IsIndeterminate="True">
                <my:GridView  IsReadOnly="True" Name="productsDG"  AutoGenerateColumns="False">
                    <my:GridView.Columns>
                       (...columns...)
                    </my:GridView.Columns>
                </my:GridView>
            </my:BusyIndicator>

        </Grid>
</Window>

【问题讨论】:

  • 删除 IsIndeterminate="True" 并尝试。
  • 不,还是一样。当我在 dispatcher.begininvoke 中放置断点时,它并没有真正到达它。在“Metoda”方法中,我有读取器从数据库中读取 0/1,0 表示不需要更新,1 表示需要更新。声明 sqlcommand 时,它会中断,并且不会完成方法。生病把它放在第一篇文章中并解释更多。
  • 是否 rbi.IsBusy = false;调试时点击?

标签: wpf busyindicator


【解决方案1】:

下面的代码对我有用。

 public Window2()
        {
            InitializeComponent();
            busyindicator1.IsBusy = true;
            Task.Factory.StartNew(CountTime);
        }

        public void CountTime()
        {
            for (int i = 0; i < 50; i++) //waiting for somthing.......
            {
                Thread.Sleep(100);
            }
            this.Dispatcher.BeginInvoke(DispatcherPriority.Send, new Action(() =>
            {
                this.busyindicator1.IsBusy = false;
            }));
        }


  <Grid>
        <tk:BusyIndicator x:Name="busyindicator1" IsBusy="False">
        <TextBlock  Name="textBlock1" Text="Sample Window"  VerticalAlignment="Center" HorizontalAlignment="Center" />
        </tk:BusyIndicator>
    </Grid>

【讨论】:

  • 不幸的是,仍然无法正常工作。它看起来像 beginInvoke 中的无休止循环
猜你喜欢
  • 2021-02-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-04-02
  • 2013-05-19
  • 1970-01-01
  • 2017-08-11
  • 1970-01-01
相关资源
最近更新 更多