编译问题的背景工作者 [英] Background worker compiling problem

查看:68
本文介绍了编译问题的背景工作者的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨。

如果有人能为我解决这个问题,我将永远感激不尽!下面的代码是对更大应用程序的地名词典部分的初步尝试。它将位置信息读入DataGridView。代码在IDE中运行正常,但在编译时,它会在我尝试运行时挂起。数据加载和问题似乎在线附近 - Me.CumbriaDataBindingSource.ResetBindings(False)。 'beep'表示已达到RunWorkerCompleted代码。



控件是: -

两个按钮(btnStart,btnStop)

a label(lblStatus)

a datagridview(datagridview1),它通过向导绑定到Access数据库。



我是我确信我保持这段代码尽可能简单,以使其工作,并且事实上我已经做了我希望的一个简单的错误,这对我来说是一个教训。我找不到它。



IDE是VS2008,开发平台是32位XP



因为它很小,所以相关代码的整个部分如下所示。



Hi.
If anyone can resolve this for me I'll be eternally grateful! The code below is an initial attempt at a gazetteer section of a much larger application. It reads location information into a DataGridView. The code runs OK in the IDE but when compiled, it hangs when I attempt to run it. The data loads and the problem appears to be somewhere around the line - Me.CumbriaDataBindingSource.ResetBindings(False). The 'beep' indicates that the RunWorkerCompleted code is reached.

Controls are:-
two buttons (btnStart, btnStop)
a label (lblStatus)
a datagridview (datagridview1)which is bound to an Access database via the wizard.

I was convinced that I'd kept this code as simple as possible in order to get it working and the fact that I've made what I hope is a simple mistake aught to be a lesson to me. I just can't find it.

The IDE is VS2008 and the development platform is 32 bit XP

As it's quite small, the entire section of the code concerned is shown below.

Public Class Form1
  Private Sub Start_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click
    'Clear the DataSet to allow the program to be re-run
    CumbriaDataSet.Clear()
    ' Disable the start button
    Me.btnStart.Enabled = False
    ' Enable to stop button
    Me.btnStop.Enabled = True
    ' Start the Background Worker
    BackgroundWorker1.RunWorkerAsync()
  End Sub

  Private Sub Stop_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStop.Click
    ' Is the Background Worker still working?
    If BackgroundWorker1.IsBusy Then
      'Cancel It
      If BackgroundWorker1.WorkerSupportsCancellation Then
        BackgroundWorker1.CancelAsync()
        ' Enable to Start Button
        Me.btnStart.Enabled = True
        ' Disable to Stop Button
        Me.btnStop.Enabled = False
      End If
    End If
  End Sub

  Private Sub BackgroundWorker1_DoWork(ByVal sender As Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
    'Fill the DataGridView from the MS Access database [Cumbria.mdb]
    Me.CumbriaDataTableAdapter.Fill(Me.CumbriaDataSet.CumbriaData)
  End Sub

  Private Sub BackgroundWorker1_RunWorkerCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles BackgroundWorker1.RunWorkerCompleted
    'If process was cancelled by the user..
    If e.Cancelled Then
      Me.lblStatus.Text = "Cancelled"
    Else
      Beep()
      'If process was completed..
      'Force the DataGridView to refresh
      Me.CumbriaDataBindingSource.ResetBindings(False)
      'Show process completed
      Me.lblStatus.Text = "Completed"
      btnStop.Enabled = False
      btnStart.Enabled = True
    End If
  End Sub

End Class





非常感谢您的帮助。这个项目的目的不是商业性的。



Rob Brookes



修改 - 未选中忽略HTML,所以代码片段会显示

推荐答案

非常感谢所有提供帮助解决此问题的人。最后,事实证明,使用后台工作者将地名词典信息(259080条记录)加载到没有UI的数据集中会更容易。然后查询该搜索的位置,仅将结果添加到列表框中。使用后台工作程序的唯一原因是,在没有帮助的情况下,数据库需要7秒才能加载到内存中,在此期间主用户界面对用户不可用,我认为7秒的启动画面有点过多。这样做不需要委托,代码在编译时运行。实际上它将是更大的GPS / GIS应用程序的一部分,但是最近才从英国军械测量局获得了地名法信息,因此可以通过搜索地名来增强基于英国网格参考的现有搜索功能。 。
Very many thanks to all who offered to help with this problem. In the end it proved easier to use the background worker to load the gazetteer information (259080 records) into a dataset which has no UI. This was then queried for the location being searched for and only the results were added to the listbox. The only reason for using the background worker was that, unaided, the database takes seven seconds to load into memory during which time the primary UI is unavailable to the user and I considered a seven second splash screen a bit too much. Doing it this way no delegates are necessary and the code runs when compiled. In fact it will be part of a much larger GPS/GIS application but the gazetteer information has only recently been made available FOC from the British Ordnance Survey office so an existing search function based upon British grid references could be augmented by one searching for place names.


您可以在程序运行时尝试调试程序(作为exe)。只需选择Debug - >附加到Visual Studio中的进程。
You could try and debug the program while it's running (as exe). Just select Debug -> Attach to Process in Visual Studio.


非常感谢Kornakar的回复以及我对延迟回复你的道歉。不幸的是,这没有显示任何问题,我到目前为止尝试的一切都未能解决问题。因此我想我会关闭这篇文章并回到标准的线程实践。后台工作者看起来像是一个简单的方法来处理应该是一个简单的任务。数据库不是我的领域,看起来它将保持这种状态!
Many thanks for the reply Kornakar and my apologies for the delay in getting back to you. Unfortunately this didn't show any problems and everything I've so far tried has failed to resolve the issue. As such I think I'll close this post and go back to standard threading practices. The background worker just looked like an easy way to handle what should have been a simple task. Databases are not my field and it looks like it will remain that way!


这篇关于编译问题的背景工作者的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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