English 中文(简体)
在执行任务时更新《协调倡议》
原标题:Updating UI while running task

我有以下法典:

        progressBar1.Minimum = 0;
        progressBar1.Maximum = Results.Count;

        foreach (MyClass cls in Results)
        {                
              progressBar1.Value += 1;

              // Go to DB and get large quantity of data
              cls.GetHistoryData();

        }

我想要做的是,把处理工作转移到另一个方面,以便取得进展。 Bar1的更新正确无误。 I've found an 这意味着,我应该能够在进展棒上使用Invoke方法,但似乎没有。

最佳回答
问题回答

页: 1 背景工序。 它支持进展,妥善处理校对之间的沟通。

你们将开始这样的新思路:

Thread t1 = new Thread(methodnametocall);
   t1.start();

void methodnametocall()
{
   this.Invoke((MethodInvoker)delegate
   {

        control to update;
    }
});

审判

progressBar1.Minimum = 0;
progressBar1.Maximum = Results.Count;

foreach (MyClass cls in Results)
{
    ThreadPool.QueueUserWorkItem((o) =>
             {
                 progressBar1.Dispatcher.BeginInvoke(
                     (Action) (() => progressBar1.Value += 1));
                 cls.GetHistoryData();
             });
}

你的这篇文章是一个成功的例子,但你正在申请世界森林论坛。 在您的案例中,您应研究如何使用http://msdn.microsoft.com/en-us/library/system.windows.threading.displer.aspx”rel=“nofollow”>Disuper<>code><>>>><>/code>>>>>>>,请通过





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...