- ubuntu12.04环境下使用kvm ioctl接口实现最简单的虚拟机
- Ubuntu 通过无线网络安装Ubuntu Server启动系统后连接无线网络的方法
- 在Ubuntu上搭建网桥的方法
- ubuntu 虚拟机上网方式及相关配置详解
CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.
这篇CFSDN的博客文章asp.net线程批量导入数据时通过ajax获取执行状态由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.
前言 。
最近因为工作中遇到一个需求,需要做了一个批量导入功能,但长时间运行没个反馈状态,很容易让人看了心急,产生各种臆想!为了解决心里障碍,写了这么个功能.
通过线程执行导入,并把正在执行的状态存入session,既共享执行状态,通过ajax调用session里的执行状态,从而实现反馈导入状态的功能! 。
上代码: 前端页面 。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
<!DOCTYPE html>
<
html
lang
=
"en"
>
<
head
>
<
meta
charset
=
"UTF-8"
>
<
title
>批量导入数据</
title
>
<
style
type
=
"text/css"
>
.pop_body_con { width: 310px; position: fixed; top: 50%; left: 50%; margin-left: -150px; background: #eee; display:none; }
.pop_body_con .pop_head { width: auto; padding: 10px 0; background: #fff; }
.pop_body_con .pop_head a { display: block; color: #717274; font-size: 12px; text-decoration: none; text-align: center; }
.pop_box { width: auto; overflow: hidden; padding: 45px 10px; }
.pop_box .pop_text { float: left; }
.pop_box .pop_text p { padding: 0; margin: 0; font-size: 12px; line-height: 18px; color: #717274;}
.pop_box .progress_bar_con { float: left; width: 220px; position: relative; z-index: 2; }
.pop_box .progress_bar_con p { margin: 0; padding: 0; font-size: 12px; color: #fff; line-height: 18px; width: 100%;
text-align: center; position: absolute; left: 0; top: 0; z-index: 4; }
.pop_box .progress_bar_con .progress_bar_start { width: 100%; height: 18px; background: #C4C0C0; }
.pop_box .progress_bar_con .progress_bar_end { width: 16%; height: 18px; background: #2bd35d; position: absolute; left: 0; top: 0; z-index: 3; }
.pop_box .progress_bar_con { float: left; }
#loading-mask { width: 100%; height: 100%; position: fixed; top: 0px; left: 0px; z-index: 0; background-color: rgba(0, 0, 0, 0.34902); display: none; }
</
style
>
<
script
src
=
"ajax-master/jquery.js"
></
script
>
<
script
>
var MyInterval;
$(function () {
$("#startImport").click(function () {
MyInterval = setInterval(getState, 1000);
});
});
function getState() {
$.ajax({
url: "test.aspx",
type: "Post",
data: { action: "getSession" },
success: function (msg) {
if (msg != "null") {
msg = eval('(' + msg + ')');
if (msg.being == 100) {
setProcessBar(1, 1);
$(".pop_body_con").hide();
$("#loading-mask").hide();
clearInterval(MyInterval);
}
else {
$(".pop_body_con").show();
$("#loading-mask").show();
setProcessBar(msg.being, msg.count)
}
}
}
});
}
function setProcessBar(exeFlag, exeMax) {
$("#progressbar_text").html(parseInt(roundFun(exeFlag / exeMax, 2) * 100) + "%");
$("#progressbar_bar").attr("style", "width:" + parseInt(roundFun(exeFlag / exeMax, 2) * 100) + "%;");
}
function roundFun(number, X) {
X = (!X ? 2 : X);
return Math.round(number * Math.pow(10, X)) / Math.pow(10, X);
}
</
script
>
</
head
>
<
body
style
=
"background-color: #fff;"
>
<
input
id
=
"startImport"
type
=
"button"
value
=
"导入数据"
/>
<
div
id
=
"loading-mask"
></
div
>
<
div
class
=
"pop_body_con"
>
<
div
class
=
"pop_head"
>
<
a
href
=
"javascript:;"
>正在导入…请勿操作!</
a
>
</
div
>
<
div
class
=
"pop_box"
>
<
div
class
=
"pop_text"
>
<
p
>导入进度:</
p
>
</
div
>
<
div
class
=
"progress_bar_con"
>
<
p
id
=
"progressbar_text"
>0%</
p
>
<
div
class
=
"progress_bar_start"
></
div
>
<
div
class
=
"progress_bar_end"
id
=
"progressbar_bar"
></
div
>
</
div
>
</
div
>
</
div
>
</
body
>
</
html
>
|
后台页面:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
using
System.Linq;
using
System.Threading;
using
System.Web;
using
System.Web.Script.Serialization;
using
System.Web.UI;
using
System.Web.UI.WebControls;
public
partial
class
test : System.Web.UI.Page
{
protected
void
Page_Load(
object
sender, EventArgs e)
{
string
action = Request.Form[
"action"
];
if
(!
string
.IsNullOrEmpty(action))
{
Hashtable temp = tmethod();
if
(temp ==
null
)
{
Thread trd =
new
Thread(
new
ParameterizedThreadStart(insertData));
trd.Start(action);
}
else
{
if
(temp[
"reCode"
].ToString() ==
"100"
)
{
Session.Remove(
"process"
);
}
}
JavaScriptSerializer ser =
new
JavaScriptSerializer();
String jsonStr = ser.Serialize(temp);
Response.Write(jsonStr);
Response.End();
}
}
public
Hashtable tmethod()
{
return
(Hashtable)Session[
"process"
];
}
private
void
insertData(
object
obj)
{
string
action = obj.ToString();
int
tCount = 100;
for
(
int
i = 0; i < tCount; i++)
{
Hashtable stateHash = setStateVal(0, i, tCount, action);
Session[
"process"
] = stateHash;
//存入session,方便共享执行状态
Thread.Sleep(500);
}
Session[
"process"
] = setStateVal(100, tCount, tCount, action);
Thread.CurrentThread.Abort();
}
private
Hashtable setStateVal(
int
code,
int
beingV,
int
CountV,
string
action)
{
Hashtable stateHash =
new
Hashtable();
stateHash[
"reCode"
] = code;
//返回状态值
stateHash[
"being"
] = beingV;
//正在执行值
stateHash[
"count"
] = CountV;
//总值
stateHash[
"action"
] = action;
//总值
return
stateHash;
}
}
|
ok,共享完毕! 。
总结 。
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作能带来一定的帮助,如果有疑问大家可以留言交流.
原文链接:http://www.cnblogs.com/LittleBai/p/6179183.html 。
最后此篇关于asp.net线程批量导入数据时通过ajax获取执行状态的文章就讲到这里了,如果你想了解更多关于asp.net线程批量导入数据时通过ajax获取执行状态的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。
当我这样做时... import numpy as np ...我可以使用它但是... import pprint as pp ...不能,因为我需要这样做... from pprint import
我第一次尝试将 OpenCV 用于 Python 3。要安装,我只需在终端中输入“pip3 install opencv-python”。当我这样做时,我在 Finder(我在 Mac 上)中看到,在
如果有一个库我将使用至少两种方法,那么以下之间在性能或内存使用方面是否有任何差异? from X import method1, method2 和 import X 最佳答案 有区别,因为在 imp
我正在从 lodash 导入一些函数,我的同事告诉我,单独导入每个函数比将它们作为一个组导入更好。 当前方法: import {fn1, fn2, fn3} from 'lodash'; 首选方法:
之间有什么关系: import WSDL 中的元素 -和- import元素和在 XML Schema ...尤其是 location 之间的关系前者和 schemaLocation 的属性后者的属性
我在从 'theano.configdefaults' 导入 'local_bitwidth' 时遇到问题。并显示以下消息: ImportError
我注意到 React 可以这样导入: import * as React from 'react'; ...或者像这样: import React from 'react'; 第一个导入 react
对于当前的项目,我必须使用矩阵中提供的信息并对其进行数学计算,以及使用 ITK/VTK 函数来显示医疗信息/渲染。基本上我必须以(我猜)50/50 的方式同时使用 matlab 例程和 VTK/ITK
当我看到 pysqlite 的示例时,SQLite 库有两个用例。 from sqlite3 import dbapi2 as sqlite3 和 import sqlite3 为什么有两种方式支持s
我使用 Anaconda Python 发行版:Python 2.7 x64 和 Windows 7 SP1 x64 Ultimate。 当我import matplotlib.pyplot时,我得到
目录 【容器】镜像导出/导入 导出 导入 带标签 不带标签,后期修改 【仓库】镜像导出/导入
我正在寻找一种导入模块的方法,以便我可以从子文件夹 project/v0 和根文件夹 project 运行脚本。/p> 我在 python 3.6 中的文件结构(这就是没有初始化文件的原因) proj
我通常被告知以下是不好的做法。 from module import * 主要原因(或者有人告诉我)是,您可能会导入一些您不想要的东西,并且它可能会隐藏另一个模块中具有类似名称的函数或类。 但是,Py
我为 urllib (python3) 编写了一个小包装器。在if中导入模块是否正确且安全? if self.response_encoding == 'gzip': import gzip
我正在 pimcore 中创建一个新站点。有没有办法导出/导入 pimcore 站点的完整数据,以便我可以导出 xml/csv 格式的 pimcore 数据进行必要的更改,然后将其导入回来? 最佳答案
在 Node JS 中测试以下模块布局,看起来本地导出的定义总是在名称冲突的情况下替换外部导出的定义(参见 B.js 中的 f1)。 A.js export const f1 = 'A' B.js e
我在使用 VBA 代码时遇到了一些问题,该代码应该将 excel 数据导入我的 Access 数据库。当我运行代码时,我收到一个运行时错误“运行时错误 438 对象不支持此属性或方法”。来自我在其他论
我有一个名为 elements 的包,其中包含按钮、trifader、海报等内容。在 Button 类中,我正在执行 from elements import * 这执行正常,当我尝试 print(p
在我长期使用 python 的经验中,我遇到了一个非常奇怪的问题。 提前我想说我想知道为什么会发生这种情况 ,而不是如何更改我的代码或如何修复它,因为我也可以做到。 我正在使用 python2.7.3
我正在更新我的包。但是,我正在为依赖项/导入而苦苦挣扎。我使用了两个冲突的包 - ggplot2和 psych及其功能 alpha当然还有 alpha ggplot2 的对象不同于 alpha psy
我是一名优秀的程序员,十分优秀!