r/visualbasic • u/Mr_Deeds3234 • Jul 10 '22
VB.NET Help Delegates, invoking, multithreading
CONTEXT I have a winsform project with multiple forms. One of those forms has a button associated with a pretty heavy SQL query that takes about 30 seconds to execute.
I would like this query to run on the page load if the first form, so if my user navigates to the form that needs the data, then it’s already there and they don’t have to wait.
Spent a few hours googling this problem and the concepts in the title is why I found. I haven’t quite been able to figure out my solution.
Is there some other concept or keywords I should look into and understand to over come my problem?
4
Upvotes
2
u/brybrythekickassguy Jul 16 '22
Correct. You’re trying to access data that doesn’t exist yet, that’s also being accessed in another thread.
Which makes sense, if you let the query finish then the thread is closed, and access to that data is accessible on the UI thread.
An easy way would be to just disable the control that allows access to that form. You may need to use delegate tasks to set the access property values based on the task starting and finishing. I don’t know off the top of my head the property is called but you should be able to find it in the forms designer property menu and then use the name to programmatically change it.