wpf里面的image控件多线程问题

运动健将 2013-09-06 08:00:05
工程需要读取一部分图片,然后显示在image控件上,但是每次读的时候,整个窗体都卡主了,我在读取过程实现了多线,但是在image.Source = imagepng的时候,还是卡

Thread thrd = new Thread(new ThreadStart(() =>
{
while (true)
{
this.Dispatcher.Invoke(new Action(() =>
{
image= imagepng;//imagepng数据在后台读取,读取过程没有贴上来

}));
}}));
thrd.Start();


不知道有什么方法能解决此问题
...全文
374 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
u012080119 2013-09-11
  • 打赏
  • 举报
回复
Invoke这个会阻塞UI线程 其实你的多线程和单线程没有什么区别。。。。 你用一个控件.Invoke和 线程锁lock(控件){}是一样的
海涵德 2013-09-11
  • 打赏
  • 举报
回复
//由于PictureBox1、Button_InsertSatelliteMapImage、ProgressBar1等均被涉及于线程,所以需要进行线程安全设置。
        delegate void PictureBoxRefreshDelegate(); // 线程刷新picturebox1
        private void PictureBoxRefresh()           // 线程刷新picturebox1
        {
            if (PictureBox1.InvokeRequired)
            {
                PictureBoxRefreshDelegate d = new PictureBoxRefreshDelegate(PictureBoxRefresh);
                this.Invoke(d);
            }
            else
            {
                PictureBox1.Refresh();
            }
        }
海涵德 2013-09-11
  • 打赏
  • 举报
回复
用“保护线程”方式对image读写。
海涵德 2013-09-11
  • 打赏
  • 举报
回复
使用“保护线程”方式使用image的读写。
lh520cq 2013-09-10
  • 打赏
  • 举报
回复
System.ComponentModel.BackgroundWorker() backgroundWorker = new System.ComponentModel.BackgroundWorker(); backgroundWorker.WorkerReportsProgress = true; backgroundWorker.WorkerSupportsCancellation = true; //回调方法 backgroundWorker.RunWorkerCompleted += new System.ComponentModel.RunWorkerCompletedEventHandler(backgroundWorker_RunWorkerCompleted); //线程执行方法 backgroundWorker.DoWork += new System.ComponentModel.DoWorkEventHandler(backgroundWorker_DoWork); backgroundWorker.RunWorkerAsync();

8,737

社区成员

发帖
与我相关
我的任务
社区描述
WPF/Silverlight相关讨论
社区管理员
  • WPF/Silverlight社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧