在保存数据数据库的同时实现进度条 [英] implementing progressbar while saving data database

查看:109
本文介绍了在保存数据数据库的同时实现进度条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个列表集合(即list1,list2 list3 ...等)
,并且我有一个xml文件(即data.xml).我将xml数据存储到合适的列表(即边缘数据)中. list1,像这样子的list2中的子数据...)
现在将xml数据存储在列表集合中之后,我想将此数据从列表保存到数据库中.保存到数据库中.

但是这整个过程很耗时间,用户不知道该过程何时完成.基本的xml文件是不固定的.我将获得包含或多或少数据的xml文件(数据xml文件的结构相同).

我想在这里实现进度条,以告知还剩下几小时,几分钟或几秒钟来完成从将xml数据存储到列表到将数据保存到数据库中的整个过程. br>
有人可以给我关于它的想法吗?


关于tarak

I have several list collections(i.e list1,list2 list3...etc)
and i have one xml file(i.e data.xml).I am storing the xml data to my suitable lists(i.e edge data in list1, subpart data in list2 like this...)
Now after storing the xml data in list collections i want to save this data from list to data base.
Till my coding is doing fine working properly and date are geting save into database.

But this entire process is time taking and user does not know when this process will completeed.Basicaly the xml file is not fixed.i will get sevaral xml file with more or less data(data structure of xml file is same).

I want to implement the progress bar here to inform how many hours or minutes or seconds left to to finise the entire process from storing xml data into list to saving data in database

can anyone give me idea about it...


with regards
tarak

推荐答案

TARAK NATH ROY写道:
TARAK NATH ROY wrote:

我想在这里实现进度条,以告知还剩下几小时,几分钟或几秒钟来完善从将xml数据存储到列表到将数据保存到数据库中的整个过程

I want to implement the progress bar here to inform how many hours or minutes or seconds left to to finise the entire process from storing xml data into list to saving data in database



您无法真正做到这一点.考虑时,进度取决于控制之外的许多因素,例如网络延迟,服务器负载,要执行的操作类型,计算机上正在运行的其他进程等等.因此,您所能做的就是(最好)给出大概要花费多长时间的粗略估计.

大多数算法通过知道需要执行多少操作然后开始计算一个操作的时间来工作.需要-然后从中推断出总时间.经过一定数量的操作后,由于在此阶段有更多的统计抽样,因此对该数字进行了细化.反复进行此操作,直到最终完成操作.



You can''t really do this. When you think about it, progress is dependent on many factors outside your control, such as network latency, server load, type of operation to be performed, other processes running on your machine, and so on. So all you can do is give (at best), a rough approximation of how long it will take.

Most algorithms work by knowing how many operations need to be performed, and then start by calculating how long one operation takes - then extrapolating the total time from this. After a certain number of operations, this figure is refined because there is greater statistical sampling at this stage. This is done over and over, until the operation is finally completed.


据我所知,不可能显示确切的时间提醒.最好的解决方案是将您的总处理划分为几个步骤,并以每个人的总时间为例进行说明
您必须执行一个包含4个步骤的任务步骤1大约占20%步骤2占30%步骤3占25%和步骤4占25%您编写了一个函数,它将在指定的时间间隔内将进度条增加到给定的值
说AutoUpdateProgress(interval,targetvalue)

示例:
AutoUpdateProgress(100,20);
{
执行步骤1
}
SetProgress(20);//完成步骤后,将进度条的值设置为= 20
AutoUpdateProgress(100,30);
{
执行步骤2
}
...
As far as I know it is not possible to show the exact time remining. the best solution is divide your total processing to sevaral steps and give each one some persentage of the total time as an example
You have to do a task which has 4 steps step 1 take approx 20% step 2 take 30% step 3 take 25 % and step 4 take 25%.you write a function wich will increment the progress bar to a given value in specified intervals
say AutoUpdateProgress(interval,targetvalue)

Example:
AutoUpdateProgress(100,20);
{
Do step 1
}
SetProgress(20);// on completion of the step on you set the progressbar value =20
AutoUpdateProgress(100,30);
{
Do step 2
}
...


首先,您必须获取数据(文件)的总大小.然后,在保存第一个文件后,您便知道花费了多长时间(以秒为单位).现在,您可以计算出保存剩余数据需要多长时间的粗略估计.

例子:
First you have to get the total size of the data (files). Then after the first file has been saved you know how long it took (in seconds). Now you can calculate a rough estimate of how long it would take to save the rest of the data.

An example:
startTime = Now

DoWork()

duration = Now - startTime   // In seconds
sizeDone = sizeDone + currentFileSize
eta = (totalSize - sizeDone) / currentFileSize * duration



但是就像皮特在回答中所说的那样,您无法预测网络错误或类似的错误.但是,如果网络在保存过程中变慢,则估计值会不断调整,因为它会不断更新.



But like Pete said in his answer, you cannot predict network errors or anything like that. However, if the network slows down during the saving process, the estimation will be adjusted accordingly because it''s constantly updated.


这篇关于在保存数据数据库的同时实现进度条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆