来自访问的反向数据更新2进度条 [英] update 2 progress bar while retrive data from access

查看:72
本文介绍了来自访问的反向数据更新2进度条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从ms访问表中提取数据。桌子。例如,包含93个字段,recordCount为4000.现在,我有2个进度条。一个用于记录计数,一个用于字段。我需要在提取数据的同时更新它们,但它不能与backgroundworker一起工作。我很难解决它。

i need to extract data from ms access table. the table. for example, contained 93 fields and the recordCount is 4000. now, i have 2 progress bar. one for the record count and one for the field. i need to update them while extracting the data but it wont work with backgroundworker. i'm having difficult trying to solve it.

While reader.Read()
    pb.Value += 1
    pb.Refresh()
    frmMain.lblStatusMain.Text = pb.Value & "/" & recordCount
    Application.DoEvents()
    dg.Rows.Add()
    For i = 0 To reader.FieldCount - 1
        dg.Rows(row).Cells(i).Value = reader(i)
        Application.DoEvents()
        If pb2.Value = pb2.Maximum Then pb2.Value = 0
        pb2.Value += 1
        pb2.Refresh()
        Application.DoEvents()
    Next i
    row += 1
End While

推荐答案

您好。



尝试更改阅读顺序和Application.DoEvents()



首先



Application.DoEvents()



然后努力工作;)



关注通过Progressbar刷新。



Hi.

Try to change the Order of the Reading and the Application.DoEvents()

First the

Application.DoEvents()

then the Hard work ;)

followed by the Progressbar Refresh.

While reader.Read()
    dg.Rows.Add()
    pb.Value += 1
    pb.Refresh()
    frmMain.lblStatusMain.Text = pb.Value & "/" & recordCount
    Application.DoEvents()
    For i = 0 To reader.FieldCount - 1
        Application.DoEvents()
        dg.Rows(row).Cells(i).Value = reader(i)
        Application.DoEvents()  'Maybe this is Useless... anyway it is 1. April, maybe it will work. 
        If pb2.Value = pb2.Maximum Then pb2.Value = 0
        pb2.Value += 1
        pb2.Refresh()
        
    Next i
    row += 1
End While





这里的MS示例: https://msdn.microsoft.com/en -us / library / bd65th41%28v = vs.90%29.aspx [ ^ ]



我用它来获取Web浏览器控件时的UI刷新加载了一个新的网页,给了一点Timegaps让它感觉像是响应。



我记得我滥用了DoEvents,在每一行。严肃的没有4月份的笑话。

有人对此很了解...



然后我添加了一个Thread.Sleep(2) DoEvent后面的努力工作。



当然Sleep会扩展Databasereads,而是看到发生的事情,而不是等待任何Endresult。



也许您可以尝试将数据库调用放入函数中,并在函数提供反馈时使用Doevents ...



来自风雨如磐的德国的快乐编码和问候......



Here the MS Example: https://msdn.microsoft.com/en-us/library/bd65th41%28v=vs.90%29.aspx[^]

I had used this to get UI refreshes when the Webbrowser Control loaded an new Webpage, to give a littlebit of Timegaps so it felt like responsive.

I remember that I abused DoEvents, in every second line. Serious no April Joke.
Someone had a good lough about it...

Then I added a Thread.Sleep(2) before the Hard Work followed by the DoEvent.

Of course the Sleep will extend the Databasereads, but rather see something happening instead of waiting for any Endresult.

Maybe You could try to put the Database Calls into a Function and use the Doevents when the Function gives feedback...

Happy Coding and Greetings from Stormy Germany...


这篇关于来自访问的反向数据更新2进度条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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