要实现的功能是 多线程创建进程(这个没办法,是调用的C++的类库)来创建图片或是修改原有图片 创建或修改后在主线程上展示图片 问题是 在没有异常出现的情况下 图片已修改完成 但没有显视 代码走到了这里this.Image.Source = bi; 但显示为空 在文件夹下可以看到修改后的图片 求解释!!!!!!!!!!!
try
{
Process p = new Process(); //这里是多线程操作的
string srt = AppDomain.CurrentDomain.BaseDirectory;
DateTime dt;
while (listCreatImage.Count > 0)
{
ForCreatImage f = listCreatImage[0];
try
{
if (File.Exists(f.FSTR))
{
dt = File.GetLastWriteTime(f.FSTR);
}
else
dt = DateTime.Now;
ProcessStartInfo ps = new ProcessStartInfo(srt + "ABC.dll", "-ss " + f.FTime.ToString() + " -y -i " + f.FfileName + " -s 120*90 -t 0.001 -f image2 " + f.FSTR);
ps.UseShellExecute = false;
ps.CreateNoWindow = true;
p.StartInfo = ps;
p.Start();
}
catch (Exception ex)
{
lock (listCreatImage)
{
listCreatImage.RemoveAt(0);
}
break;
}
while (dt == File.GetLastWriteTime(f.FSTR))//判断文件是否创建或是修改
{
Thread.Sleep(1000);
}
githis.Invoke(listCreatImage[0]);
lock (listCreatImage)
{//主线程会不定期的向list里面增加
listCreatImage.RemoveAt(0);
} }
p.Close();
p.Dispose(); }
catch (Exception ex)
{
}
lock (o)
{
createImageThread.Abort();
}
以上是创建文件或是修改文件//通过上部分的githis.Invoke(listCreatImage[0]);的实现
try
{
BitmapImage bi = new BitmapImage();
FileStream fs = File.Open(imageSource, FileMode.Open);
if (fs.CanRead)
{
bi.BeginInit();
bi.StreamSource = fs;
DateTime dt = DateTime.Now;
bi.EndInit();
int d = bi.PixelWidth;
this.Image.Source = bi; //代码每次都会走到这里
fs.Close();
fs.Dispose();
}
else //从来没到这里
{
}
}
catch (Exception)
{
}WPF多线程图片
try
{
Process p = new Process(); //这里是多线程操作的
string srt = AppDomain.CurrentDomain.BaseDirectory;
DateTime dt;
while (listCreatImage.Count > 0)
{
ForCreatImage f = listCreatImage[0];
try
{
if (File.Exists(f.FSTR))
{
dt = File.GetLastWriteTime(f.FSTR);
}
else
dt = DateTime.Now;
ProcessStartInfo ps = new ProcessStartInfo(srt + "ABC.dll", "-ss " + f.FTime.ToString() + " -y -i " + f.FfileName + " -s 120*90 -t 0.001 -f image2 " + f.FSTR);
ps.UseShellExecute = false;
ps.CreateNoWindow = true;
p.StartInfo = ps;
p.Start();
}
catch (Exception ex)
{
lock (listCreatImage)
{
listCreatImage.RemoveAt(0);
}
break;
}
while (dt == File.GetLastWriteTime(f.FSTR))//判断文件是否创建或是修改
{
Thread.Sleep(1000);
}
githis.Invoke(listCreatImage[0]);
lock (listCreatImage)
{//主线程会不定期的向list里面增加
listCreatImage.RemoveAt(0);
} }
p.Close();
p.Dispose(); }
catch (Exception ex)
{
}
lock (o)
{
createImageThread.Abort();
}
以上是创建文件或是修改文件//通过上部分的githis.Invoke(listCreatImage[0]);的实现
try
{
BitmapImage bi = new BitmapImage();
FileStream fs = File.Open(imageSource, FileMode.Open);
if (fs.CanRead)
{
bi.BeginInit();
bi.StreamSource = fs;
DateTime dt = DateTime.Now;
bi.EndInit();
int d = bi.PixelWidth;
this.Image.Source = bi; //代码每次都会走到这里
fs.Close();
fs.Dispose();
}
else //从来没到这里
{
}
}
catch (Exception)
{
}WPF多线程图片
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货