[RESOLVED] [2008] Raising an event before loading data
As it stands, when I click a button to load the data the application lags and looks as though it has locked up although it has not. There are a lot (10,000) of records to load in some cases.
I thought I could just change my status strip text to dispay "Loading database" while it's loading.
So, I raise an event (dbloading) in the "load db" button.click event before calling the procedure to load the data. When that event is raised, I change the status strip text.... but it does not work.
Any ideas? Here's my code:
Code:
Private Sub btnLoad_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLoad.Click
jnATM = Me.atmJobNum
RaiseEvent dbLoading(jnATM)
' Fill the DataSet and bind the fields
FillDataSetAndView(jnATM)
BindFields()
' Show the current record position
ShowPosition()
RaiseEvent dbLoaded(jnATM)
btnLoad.Visible = False
End Sub
Here's the code for the event handler:
Code:
Private Sub AtmDbModule1_dbLoading(ByVal jnATM As String) Handles AtmDbModule1.dbLoading
Me.ToolStripStatusLabel1.Text = "Loading ATM Job#: " & jnATM
End Sub
Re: [2008] Raising an event before loading data
Is the data loading on another thread? If so, you'll need to invoke a delegate.
Otherwise, try putting "My.Application.DoEvents()" in there after the RaiseEvent()
Re: [2008] Raising an event before loading data
Unfortunately, my knowledge of Threads is non-existent. So, I don't know how to answer your question. If I were guessing, I would say no.
I tried your suggestion. I get an intellisense error saying "DoEvents" is not a member of My.application
hmmmm.
Re: [2008] Raising an event before loading data
Try just "Application.DoEvents()" and if it don't like that: "Threading.Thread.Sleep(0)"
Re: [2008] Raising an event before loading data
I shall try that. I need to learn about this "threading" stuff.
I figured out a work-around: I added a timer control, set the interval to 2 seconds. I Start the timer and raise the event when I click the button. On the timer.tick event I run the db load procedure. It seems to work.
It seems like there would be a better way. Something that wouldn't make the app look like it's locked up.
Re: [2008] Raising an event before loading data
Re: [2008] Raising an event before loading data
Thanks!
Problem solved, for now.