积极答复者
執行 webclient 內存就不斷增加

问题
答案
-
不要加太多图片,不是这样做的。你要么把很多图片,拼成一个大的Writeablemap再输出。如果你机器只有4G,内存在2.5G以上,你就没办法再回收回来了,不过如果占用不大就用GC就可以回收的。
"长连接"是模拟的Socket。Silverlight本来就有Socket通讯,你也可以用WCF的双工。以便达到一直服务器和客户端通讯.
努力!完成了js解析器,还差一个svg插件,一个绘图程序,做好自己,呵呵~!- 已标记为答案 Daoping Liu - MSFTModerator 2011年9月9日 2:11
全部回复
-
-
using System;
using System.Collections.Generic;
using System.Net;
using System.Windows;
using System.Windows.Browser;
using System.Windows.Controls;
using System.Windows.Media.Imaging;
using QueueLoad.controls;
using QueueLoad.ServiceReference1;
using System.Windows.Shapes;
using System.Windows.Media;
using System.Windows.Media.Effects;namespace QueueLoad
{
public partial class MainPage : UserControl
{
int pageDownloads = 0;
WebClient _wc = new WebClient();public MainPage()
{
InitializeComponent();
ServiceReference1.Service1Client client = new ServiceReference1.Service1Client();
client.getprojectimageinfoAsync("別墅外牆");
client.getprojectimageinfoCompleted += new EventHandler<ServiceReference1.getprojectimageinfoCompletedEventArgs>(client_getprojectimageinfoCompleted);
}
Image imgItem;
Grid grid;
TextBlock tb;
List<YHProject> p;
void client_getprojectimageinfoCompleted(object sender, ServiceReference1.getprojectimageinfoCompletedEventArgs e)
{
p = new List<YHProject>(e.Result);
for (int i = 0; i < p.Count; i++)
{
grid = new Grid();
imgItem = new Image();
imgItem.Width = 100;
imgItem.Height = 70;
imgItem.Name = "img" + (i + 1).ToString();
imgItem.Margin = new Thickness(5, 0, 0, 0);
//imgItem.MouseLeftButtonDown += new MouseButtonEventHandler(imgItem_MouseLeftButtonDown);
//imgItem.MouseEnter += new MouseEventHandler(imgDown_MouseEnter);
//imgItem.MouseLeave += new MouseEventHandler(imgDown_MouseEnter);
Loading ld = new Loading();
ld.VerticalAlignment = VerticalAlignment.Center;
ld.HorizontalAlignment = HorizontalAlignment.Center;
Rectangle r = new Rectangle();
r.Width = 50;
r.Height = 20;
r.Margin = new Thickness(45, 60, 0, 0);
r.Fill = new SolidColorBrush(Colors.Black);
tb = new TextBlock();
tb.Margin = new Thickness(53, 60, 0, 0);
tb.Name = "tb" + (i + 1).ToString();
tb.Foreground = new SolidColorBrush(Colors.White);
grid.Children.Add(ld);
grid.Children.Add(imgItem);
grid.Children.Add(r);
grid.Children.Add(tb);
this.stkpnlImage.Children.Add(grid);
}_wc.OpenReadCompleted += new OpenReadCompletedEventHandler(_wc_OpenReadCompleted);
LoadImage();
}
Image im;
void _wc_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
if (e.Error == null)
{
BitmapImage _bitMap = new BitmapImage();
_bitMap.SetSource(e.Result);
im = stkpnlImage.FindName("img" + (i + 1).ToString()) as Image;
tb = this.stkpnlImage.FindName("tb" + (i + 1).ToString()) as TextBlock;
tb.Text = ((i + 1).ToString()) + "/" + p.Count;
im.Source = _bitMap;
im.Source = null;
e.Result.Dispose();
i++;
LoadImage();//关键,继续加载下一个(是不是有点ajax中http长连接的意思,呵)
}
}
private void btnLoad_Click(object sender, RoutedEventArgs e)
{
LoadImage();
}
int i=0;
void LoadImage()
{
if (i < p.Count)
{
if (p != null && p.Count > 0)
{
string[] url = p[i].imageurl.Split('/');
string urls = url[1] + "/" + url[2] + "/" + url[3];
_wc.OpenReadAsync(new Uri(urls, UriKind.Relative));
}
}}
}
} -
不要加太多图片,不是这样做的。你要么把很多图片,拼成一个大的Writeablemap再输出。如果你机器只有4G,内存在2.5G以上,你就没办法再回收回来了,不过如果占用不大就用GC就可以回收的。
"长连接"是模拟的Socket。Silverlight本来就有Socket通讯,你也可以用WCF的双工。以便达到一直服务器和客户端通讯.
努力!完成了js解析器,还差一个svg插件,一个绘图程序,做好自己,呵呵~!- 已标记为答案 Daoping Liu - MSFTModerator 2011年9月9日 2:11