代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
Asp.NET
】
利用多线程,生成大量图片
作者:
/ 发布于
2017/2/6
/
390
如果图片文件名重复,则会报错:‘GDI+ 中发生一般性错误。ExternalException’
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Configuration; using System.Data; using System.Threading; using System.Data.SqlClient; using UBIQ.ETS.TIC.NS.Biz; using System.IO; namespace WebMultiThread { public partial class ThreadGenPict : System.Web.UI.Page { private DataTable threadOneResult; private DataTable threadTwoResult; private DataTable threadThreeResult; protected void Page_Load(object sender, EventArgs e) { if (!Directory.Exists(outdir)) Directory.CreateDirectory(outdir); if (threadOneResult == null) { threadOneResult = new DataTable(); threadOneResult.Columns.Add(new DataColumn()); } if (threadTwoResult == null) { threadTwoResult = new DataTable(); threadTwoResult.Columns.Add(new DataColumn()); } if (threadThreeResult == null) { threadThreeResult = new DataTable(); threadThreeResult.Columns.Add(new DataColumn()); } } public void AsyncCallsWithThreadPool() { int row1 = 10; int row2 = 5000; int row3 = 10; ThreadPool.QueueUserWorkItem(ThreadOne, row1); ThreadPool.QueueUserWorkItem(ThreadTwo, row2); ThreadPool.QueueUserWorkItem(ThreadThree, row3); //while (threadOneResult.Rows.Count == row1 || // threadTwoResult.Rows.Count == row2 || // threadThreeResult.Rows.Count == row3) //{ // Thread.Sleep(10000); //} //int sleep = int.Parse(TextBox1.Text); //Thread.Sleep(sleep*1000); //threadOneResult.Merge(threadTwoResult); //threadOneResult.Merge(threadThreeResult); //DetailsView1.DataSource = threadOneResult; //DetailsView1.DataBind(); } string outdir = AppDomain.CurrentDomain.BaseDirectory + @"OutImage\"; string backfile = AppDomain.CurrentDomain.BaseDirectory + "TicketBack.jpg"; private void ThreadOne(object state) { int i = 0; int max = int.Parse(state.ToString()); while (true) { try { BizTool.SaveTicketImage(BizTool.GetTicketCode() + "Type1" + i.ToString(), outdir + BizTool.GetTicketCode() + "Type1" + i.ToString() + ".jpg", "Type1", "11元", backfile); } catch (IOException ex) { BizTool.MsgToFile(ex.Message); } i++; if (i > max) break; DataRow row = threadOneResult.NewRow(); row[0] = (BizTool.GetTicketCode() + "Type1" + i.ToString()); threadOneResult.Rows.Add(row); } } private void ThreadTwo(object state) { int i = 0; int max = int.Parse(state.ToString()); while (true) { try { BizTool.SaveTicketImage(BizTool.GetTicketCode() + "Type2" + i.ToString(), outdir + BizTool.GetTicketCode() + "Type2" + i.ToString() + ".jpg", "Type2", "12元", backfile); } catch (IOException ex) { BizTool.MsgToFile(ex.Message); } i++; if (i > max) break; DataRow row = threadTwoResult.NewRow(); row[0] = (BizTool.GetTicketCode() + "Type2" + i.ToString()); threadTwoResult.Rows.Add(row); } } private void ThreadThree(object state) { int i = 0; int max = int.Parse(state.ToString()); while (true) { try { BizTool.SaveTicketImage(BizTool.GetTicketCode() + "Type3" + i.ToString(), outdir + BizTool.GetTicketCode() + "Type3" + i.ToString() + ".jpg", "Type3", "13元", backfile); } catch (IOException ex) { BizTool.MsgToFile(ex.Message); } i++; if (i > max) break; DataRow row = threadThreeResult.NewRow(); row[0] = (BizTool.GetTicketCode() + "Type3" + i.ToString()); threadThreeResult.Rows.Add(row); } } protected void Button1_Click(object sender, EventArgs e) { Response.Redirect("http://www.baidu.com"); } protected void Button2_Click(object sender, EventArgs e) { Response.Redirect("Default.aspx"); } protected void Button3_Click(object sender, EventArgs e) { AsyncCallsWithThreadPool(); } } }
试试其它关键字
同语言下
.
gzip压缩
.
实现http多线程断点续传下载文件
.
实现多线程断点续传下载大文件
.
生成字符串的 CheckSum
.
根据 UserAgent 获取浏览器的类型和版本
.
根据 Agent 判断是否是智能手机
.
隐藏手机号中间四位为*方法
.
合并图片(二维码和其他图片合并)
.
ASP.NET CORE中判断是否移动端打开网页
.
ASP.NET(C#)实现页面计时(定时)自动跳转
可能有用的
.
gzip压缩
.
实现http多线程断点续传下载文件
.
实现多线程断点续传下载大文件
.
生成字符串的 CheckSum
.
根据 UserAgent 获取浏览器的类型和版本
.
根据 Agent 判断是否是智能手机
.
隐藏手机号中间四位为*方法
.
合并图片(二维码和其他图片合并)
.
ASP.NET CORE中判断是否移动端打开网页
.
ASP.NET(C#)实现页面计时(定时)自动跳转
贡献的其它代码
Label
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3