C# 一个窗体加载一个窗体显示动画 但是 加载的时候动画卡 为什么 线程有问题么?还是机器配置关系?using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Data;
using System.Threading;
using System.Windows.Threading;namespace WpfApplication1
{
/// <summary>
/// Window1.xaml 的交互逻辑
/// </summary>
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
}
public void winLoad()
{
readXML xml = new readXML();
DataTable table = xml.ReadMiniDTXml();
for (int i = 0; i < table.Rows.Count; i++)
{
Image user = new Image();
user.Name = "u" + (i + 1).ToString();
user.Source = new BitmapImage(new Uri(Environment.CurrentDirectory + table.Rows[i]["path1"].ToString().Trim())); user.Width = 100;
user.Height = 100;
this.stackPanel_Image.Children.Add(user);
}
}
Thread newWindowThread;
public delegate void AddButtonDelegate();
private void Window_Loaded(object sender, RoutedEventArgs e)
{
//加载进程
Thread thread = new Thread(DO);
// thread.IsBackground = true;
thread.Start();
//动画窗体进程
newWindowThread = new Thread(new ThreadStart(ThreadStartingPoint));
newWindowThread.SetApartmentState(ApartmentState.STA);
//newWindowThread.IsBackground = true;
newWindowThread.Start();
}
/// <summary>
/// 开启新窗体 解决因加载,动画卡的问题
/// </summary>
private void ThreadStartingPoint()
{
Window2 tempWindow = new Window2();
tempWindow.Show();
System.Windows.Threading.Dispatcher.Run();
}
public void AddImage()
{
winLoad();
System.Windows.Application.Current.
} void Window1_ContentRendered(object sender, EventArgs e)
{
newWindowThread.Abort(); //终止动画窗体进程
}
public void DO()
{ System.Windows.Application.Current.Dispatcher.BeginInvoke(new AddButtonDelegate(AddImage), DispatcherPriority.ContextIdle); }
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Data;
using System.Threading;
using System.Windows.Threading;namespace WpfApplication1
{
/// <summary>
/// Window1.xaml 的交互逻辑
/// </summary>
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
}
public void winLoad()
{
readXML xml = new readXML();
DataTable table = xml.ReadMiniDTXml();
for (int i = 0; i < table.Rows.Count; i++)
{
Image user = new Image();
user.Name = "u" + (i + 1).ToString();
user.Source = new BitmapImage(new Uri(Environment.CurrentDirectory + table.Rows[i]["path1"].ToString().Trim())); user.Width = 100;
user.Height = 100;
this.stackPanel_Image.Children.Add(user);
}
}
Thread newWindowThread;
public delegate void AddButtonDelegate();
private void Window_Loaded(object sender, RoutedEventArgs e)
{
//加载进程
Thread thread = new Thread(DO);
// thread.IsBackground = true;
thread.Start();
//动画窗体进程
newWindowThread = new Thread(new ThreadStart(ThreadStartingPoint));
newWindowThread.SetApartmentState(ApartmentState.STA);
//newWindowThread.IsBackground = true;
newWindowThread.Start();
}
/// <summary>
/// 开启新窗体 解决因加载,动画卡的问题
/// </summary>
private void ThreadStartingPoint()
{
Window2 tempWindow = new Window2();
tempWindow.Show();
System.Windows.Threading.Dispatcher.Run();
}
public void AddImage()
{
winLoad();
System.Windows.Application.Current.
} void Window1_ContentRendered(object sender, EventArgs e)
{
newWindowThread.Abort(); //终止动画窗体进程
}
public void DO()
{ System.Windows.Application.Current.Dispatcher.BeginInvoke(new AddButtonDelegate(AddImage), DispatcherPriority.ContextIdle); }
}
}
解决方案 »
- C#编写的windows服务,怎样访问网络映射驱动器
- 怎样让表单提交不刷新?刷新页面不重复提交?
- >>>>>>C#编的Windows 服务程序,不进入OnShutdown???
- XAML与C#是不是完全映射的关系?
- 如何控制上传图片时让它大小为一寸,文件大小为20K
- DataGridBoolColumn问题
- C#如果判断文件夹是否已经通过资源管理器打开?
- VS2008设计界面有图片,在浏览器中查看显示不出来
- 多线程使用HttpWebRequest出现OutOfMemoryException错误
- 一个Request传参数的小问题,各位老大给个面子看一下。
- c# vs2005中tabpage的问题
- 求高手 加载大量图片 怎么优化内存?
通过调用 void Worker_DoWork(object sender, DoWorkEventArgs e)
void Worker_ProgressChanged(object sender, ProgressChangedEventArgs e)
void _Worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)等事件来实现进度显示,动画缓冲显示之类的.具体可以参看我的源代码参考:
http://download.csdn.net/source/2843606