I am uploading data to a Microsoft SQL database, and I decided to use a thread to allow the user to see the progress. All code worked fine without threads, but inside the thread. Below is the code that is causing problems. As I step through the code in the debugger, when I hit the first line of code below, I am sent to the Window, and I am kicked out of the debugger, as if all code has completed executing. Any ideas.
rs = app.dbSQL.SQLSelect(SQL)
If app.dbSQL.Error Then
//Put messages in an object to be displayed outside of the thread
lbClaimsMessagesCol1.Append("Fail - Claim sheet name not found in database")
lbClaimsMessagesCol2.Append("0")
End If
dont share a db across a thread and another thread or the app etc
and dont share any of its properties between threads and anything else
when you think you need to realize you will have weird hard to find but - just dont
IF the thread alls this method in APP then its “part of the thread” - everything called from a threads run method is
and in that case I suspect lbClaimsMessagesCol1 is a listbox and that IS UI and you cannot touch UI from a thread
lbClaimsMessagesCol1 is a property of the window that I am using to share information in and out of the thread. If this is a no-no,
how do you pass information from a thread?
lb is an array property of the window that I was using to store information to be passed to the listbox, providing progress to the user. I will now make a thread subclass with private properties rather than putting the properties in the window.
What still confuses me is that I get an error if I attempt to access a UI, but when I execute the recordset code I am passed back to the window (even though I am stepping through the code one line at a time in debug mode), and there are no error notifications.
if its JUST an array that should be ok from a thread afaict
but its hard to tell for sure from that short snippet what the issue might be
nothing obvious
Well have a look on examples -> Desktop -> UpdateUIFromThread-> UIThreadingWithTask, is closely to what Norman mentioned. and it works quite well, I start to use it in few places just to avoid the progress rainbow wheel blocking the interface.
If I do not use the database in the App, and put the database in the method I am running, then it works fine. I still do not understand why the debugger does not work.
Thanks everyone for all the assistance. I love this forum.
I was successful at updating the UI when updating a database from all Excel files contained in a directory. Now I need to take data from a listbox and update a database. Since I cannot access any UI from the thread how can this be done. I could write the listbox information to a property in the thread, but that would add a substantail amount of time to the execution. Is there a more efficient method?
dim s as string = myListBox.Cell(-1,-1)
...
dim rows() as string = split(s, EndOfLine)
for i as integer = 0 to Ubound(rows)
dim cols() as string = split(rows(i), chr(9)) // tab
...
next
That puts the entire contents of the listbox into the string in one go. Hand that to your thread. You basically get a tab-delimited file.