C# WinForm自定义添加控件,类似百度云PC端,内存占用厉害

cmflovekm cmflovekm 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
C#自定义加载上传列表控件,类似百度云PC端,但是使用线程动态加载时出现内存占用明显,当数量超过100时效率明显下降,内存占用越来越大。
{
CurrentUpLoadList = MyXmlOp.GetLoadList(CurrentUser.UID);//这是获取的图片信息列表(很多1000+)
FormGetUpListThread = new Thread(new ThreadStart(ThreadFunc));
FormGetUpListThread.Start();
}

Thread FormGetUpListThread;
private void ThreadFunc()
{
int Count = CurrentUpLoadList.Count;
SetUpLoadListTh(Count);
}

private void SetUpLoadListTh(int Count)//内存占用比较厉害,所以限制最大数量为50
{
foreach(MyUpLoadInfo MyUp in CurrentUpLoadList)
{
if (MyUp.FileLength / 1024 < 10)
return;

//MyUpLoadControl MewControl = new MyUpLoadControl();//这个是封装的自定义控件,与下面代码生成的是一样的,效率也一至,也是一样存在内存占用问题
//MewControl.Dock = DockStyle.Top;
//MewControl.Tag = MyUp.FileFullName;
//Image Img = Image.FromFile(MyUp.FileFullName);
//MewControl.PicB.Image = new Bitmap(Img);
//Img.Dispose();
//AddListToUp(xtraTabPageUp, MewControl);

Panel nPanel = new Panel();
//DevExpress.XtraEditors.PanelControl nPanel = new DevExpress.XtraEditors.PanelControl();
nPanel.Height = 60;
nPanel.Width = this.xtraTabPageUp.Width - 20;
nPanel.Tag = "panel_" + MyUp.FileFullName;
nPanel.Dock = DockStyle.Top;
AddListToUp(xtraTabPageUp, nPanel);

Panel nPanelLine = new Panel();
nPanelLine.Dock = DockStyle.Top;
nPanelLine.Height = 1;
nPanelLine.BackColor = System.Drawing.Color.DarkGray;
//nPanelLine.Parent = nPanel;
AddListToUp(nPanel, nPanelLine);

PictureBox PicB = new PictureBox();
Image Img = Image.FromFile(MyUp.FileFullName);
PicB.Image = new Bitmap(Img);
Img.Dispose();
PicB.BackgroundImageLayout = ImageLayout.Zoom;
PicB.Size = new System.Drawing.Size(50, 50);
PicB.Location = new Point(10, 5);
AddListToUp(nPanel, PicB);

//System.Windows.Forms.ProgressBar pra = new System.Windows.Forms.ProgressBar();
DevExpress.XtraEditors.ProgressBar pra = new DevExpress.XtraEditors.ProgressBar();
pra.Tag = "pra_" + MyUp.FileFullName;
pra.ForeColor = System.Drawing.SystemColors.Highlight;
pra.Height = 20;
pra.Width = 220;
//pra.Parent = nPanel;
pra.Location = new Point(400, 20);
AddListToUp(nPanel, pra);


DevExpress.XtraEditors.LabelControl lbl = new DevExpress.XtraEditors.LabelControl();
//lbl.Parent = nPanel;
lbl.Tag = "labelUpName_" + MyUp.FileFullName;
lbl.Text = MyUp.FileName;
lbl.Location = new Point(80, 10);
AddListToUp(nPanel, lbl);

DevExpress.XtraEditors.LabelControl lbl1 = new DevExpress.XtraEditors.LabelControl();
//lbl1.Parent = nPanel;
lbl1.Tag = "lblTime_" + MyUp.FileFullName;
lbl1.Text = " --";
lbl1.Location = new Point(340, 22);
lbl1.ForeColor = System.Drawing.SystemColors.GrayText;
AddListToUp(nPanel, lbl1);

DevExpress.XtraEditors.LabelControl lbl2 = new DevExpress.XtraEditors.LabelControl();
//lbl2.Parent = nPanel;
lbl2.Tag = "lblSpeed_" + MyUp.FileFullName;
lbl2.Text = "0KB/S";
lbl2.Location = new Point(640, 22);
lbl2.ForeColor = System.Drawing.SystemColors.Highlight;
AddListToUp(nPanel, lbl2);

DevExpress.XtraEditors.LabelControl lbl3 = new DevExpress.XtraEditors.LabelControl();
//lbl3.Parent = nPanel;
lbl3.Tag = "lblState_" + MyUp.FileFullName;
lbl3.Text = MyUp.HasLoadLength / 1024 + "KB/" + MyUp.FileLength / 1024 + "KB";
lbl3.Location = new Point(80, 35);
lbl3.ForeColor = System.Drawing.SystemColors.GrayText;
AddListToUp(nPanel, lbl3);
}
}
private delegate void MyDelegateUI();
//List<string> DelegateNames = new List<string>();
void AddListToUp(Control Par,Control ctr)//若不使用委托,线程中奖无法对一些控件进行操作
{
if (xtraTabPageUp.InvokeRequired)
{
MyDelegateUI d = delegate
{
Par.Controls.Add(ctr);
};
Par.Invoke(d);
}
else
{
Par.Controls.Add(ctr);
}
}
...全文

相关推荐

C# Winform调用百度接口实现人脸识别教程源码完整版!!!(步骤清晰)

C# Winform调用百度接口实现人脸识别教程源码完整版 这是一篇完整的人脸识别系统,源码已经附上,按照我的步骤,可以实现人脸识别登录呦!!!当然,前提是你有耐心看完! 目录C# Winform调用百度接口实现人脸识别教程源码完整版第一步,在百度创建你的人脸识别应用第二步,使用API Key和Secret Key,获取 AssetToken第三步,封装图片信息类Face,保存图像信息第四步,定义人脸注册和搜索类FaceOperate第五步,绘制videoSourcePlayer控件,对人脸进行拍摄第五步,

猴麦麦

《模式识别与数据挖掘》配套PPT课件

《模式识别与数据挖掘》配套PPT课件

Bryan Ding

科技成果转化项目进场交易前,评估备案环节需要准备哪些材料?_8.docx

科易网基于AI模型+行业大数据,在技术转移、成果转化、技术经纪、知识产权、产业创新、科技招商等垂直领域的多样化应用场景,推出科技创新领域的AI+工具与数智化解决方案,推动科技创新与产业创新智能化发展。

BIZKEEN

人工智能通识教育(中职版)课程标准+PPT课件+部分素材+电子活页+在线考核

人工智能通识教育(中职版)课程标准+PPT课件+部分素材+电子活页+在线考核

Bryan Ding

跨境电商供应链管理(AIGC版)课件+教案+参考答案

跨境电商供应链管理(AIGC版)课件+教案+参考答案

Bryan Ding
评论 2
收藏 已收藏
分享
返回顶部
cmflovekm
C# 111,129 成员 642,539 内容