[英]Prevent a WinForms PictureBox animated GIF from pausing during processing?
I have a form with 2 controls on it. 我有一个带有2个控件的表单。 Control 1 has several search criteria and the user can click a button to start the search.
控件1具有多个搜索条件,用户可以单击按钮开始搜索。 Control 2 has a GridView that will display the search results and also has a PictureBox with an animated Gif in it.
控件2具有一个GridView,它将显示搜索结果,还具有一个PictureBox,其中带有动画Gif。
Control 1 has a method in it that has a nested foreach loop that takes upwards of 5 minutes to complete (depends upon the search criteria, sometimes it finishes almost instantly). 控件1中有一个方法,其中包含嵌套的foreach循环,最多需要5分钟才能完成(取决于搜索条件,有时它几乎立即完成)。
What happens is that I call a method on Control 2 that makes the PictureBox visible and the animated Gif starts running. 发生的是,我在控件2上调用了一个使PictureBox可见并且动画Gif开始运行的方法。 As soon as the foreach loop is hit that takes a while, the image completely stops.
一旦foreach循环被击中需要一段时间,图像就会完全停止。 Whenever I show any MessageBoxes the image starts running again (I presume it is because the MessageBox is blocking).
每当我显示任何MessageBox时,图像都会再次开始运行(我想是因为MessageBox被阻止了)。 As soon as the MessageBox is closed, the image stops animating.
一旦关闭MessageBox,图像就会停止动画显示。
I presume I will need to utilize something with threading, but everything I am trying (ImageAnimator, Thread calling a method that calls Invoke, etc.) all seem to not work. 我想我将需要在线程中使用某些东西,但是我正在尝试的所有东西(ImageAnimator,Thread调用了调用Invoke的方法等)都似乎不起作用。 Any hints what events/libraries I need to work with in order to make this work?
有什么提示我需要配合使用哪些事件/库才能使其工作? Any good examples to follow?
有什么好的榜样吗?
You long running code runs in the GUI-Thread and blocks the internal message loop, so any GUI is stopping. 您长时间运行的代码在GUI线程中运行,并阻塞了内部消息循环,因此任何GUI都将停止。 Try to run your long running code in a separate worker thread.
尝试在单独的工作线程中运行长时间运行的代码。
2 words: BackgroundWorker class. 2个字:BackgroundWorker类。 http://msdn.microsoft.com/en-us/library/waw3xexc.aspx
http://msdn.microsoft.com/zh-CN/library/waw3xexc.aspx
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.