Xamarin Android C中的进度条和线程#

时间:2018-05-21 10:30:07

标签: c# android xamarin progress-bar threadpool

我尝试使用此方法加载SQL。当我单击按钮登录时,该方法正在运行并显示圆形进度对话框,但在完成进度对话框或线程完成后,仍会出现圆形进度对话框。

我希望使用RunOnUiThread()使circleprogressbar消失。我怎样才能弄清楚我的代码有什么问题?顺便说一下,我在我的片段中运行了这个,所以我需要使用Activity来调用RunOnUiThread函数。

circleprogressbar.Visibility = ViewStates.Visible;
new Thread(new ThreadStart(delegate
    {

       while (progressValue < 100)
           {
               progressValue += 10;
               circleprogressbar.Progress = progressValue;
                Thread.Sleep(2000);
           }
  Activity.RunOnUiThread(() => { circleprogressbar.Visibility = ViewStates.Invisible; });
            })).Start();

1 个答案:

答案 0 :(得分:1)

我建议创建event来处理这种情况,如下所示:

def log(foo: String)(implicit line: sourcecode.Line, file: sourcecode.File) = {
  println(s"${file.value}:${line.value} $foo")
}

log("Foooooo") // sourcecode/shared/src/test/scala/sourcecode/Tests.scala:86 Fooooo

我编写了没有智能感知的代码,因此一些声明或方法调用可能需要进行一些检查。这个解决方案不是很好,但如果你现在需要它 - 这会有所帮助。 另外,我建议你阅读Xamarin Forms - Messaging Center。 在您的情况下使用此工具会更好。

相关问题