
我尝试了一个故事板方法但最终变得非常缓慢.
那么还有Thread.sleep的替代方案来减慢我的循环吗?
voID DrawGasket(object sender,DoWorkEventArgs e) { Random rnd = new Random(); color color = colors.White; while (Counter <= noOfPx) { switch (rnd.Next(3)) { case 0: m_lastPoint.X = (m_top.X + m_lastPoint.X)/2; m_lastPoint.Y = (m_top.Y + m_lastPoint.Y)/2; color = colors.White; break; case 1: m_lastPoint.X = (m_left.X + m_lastPoint.X)/2; m_lastPoint.Y = (m_left.Y + m_lastPoint.Y)/2; color = colors.Orange; break; case 2: m_lastPoint.X = (m_right.X + m_lastPoint.X)/2; m_lastPoint.Y = (m_right.Y + m_lastPoint.Y)/2; color = colors.Purple; break; } dispatcher.BeginInvoke(() => { var px = new Rectangle { Height = m_pxSize,WIDth = m_pxSize,Fill = new SolIDcolorBrush(color) }; Canvas.Settop(px,m_lastPoint.Y); Canvas.Setleft(px,m_lastPoint.X); can.Children.Add(px); lblCounter.Text = Counter.ToString(); }); Counter++; Thread.Sleep(1); } }解决方法 难道你不能只通过循环而不是每次迭代睡眠N次迭代吗? 总结 以上是内存溢出为你收集整理的c# – Thread.Sleep(1);对于Silverlight动画来说太慢了,还有其他选择吗?全部内容,希望文章能够帮你解决c# – Thread.Sleep(1);对于Silverlight动画来说太慢了,还有其他选择吗?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)