Avatar of jamesspo
jamesspo asked on

vb.net Creating threads for SQL query and GIF

Hi Experts.
(using vb.net, Visual studio 2005 Pro)
I'm really not sure why I cannot make this work. I  have a windows form (form1) which contains (not surprisingly) contains functions and subs. On a tab I have a groupBox containing a button, label and pictureBox.

Like many who have gone before me, I would like to show an animated GIF next to the button in the groupBox while a long (1-2 minites) SQL query executes.

class form1
   Private Sub btnUpdate_Click(ByVal sender...)
end class

if we assume that the btnUpdate_Click event which triggers the following code;
Private Sub btnUpdate_Click(ByVal sender...)
   connect to database
   run large "SELECT INTO" command
end sub

How do I thread the sql query and the gif to make both run at the same time??

I have tried
1) Creating 2 threads at the start of the form1 class, then calling them for a sub which updates the database and another sub the displays the gif.
2) Creating 1 thread for form1, in which the gif is placed and another thread for the SQL query sub

Neither work. I get cross-threading errors (Visual studio 2005). I'm using the following commands.

Dim thdSQL As Thread
thdSQL = New Thread(AddressOf updateSQL)
thdSQL .Start()

Can anyone suggest exactly how I run the SQL "SELECT INTO" and "animated gif" in different threads so that I get the desired effect?
.NET ProgrammingVisual Basic.NET

Avatar of undefined
Last Comment

8/22/2022 - Mon

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question

Hi Rachitkohi,
Thanks for replying. I'll be able to retest later today and let you know who it went. Before I do, can I ask you a question:
Do you know whether turing off CheckForIllegalCrossThreadCalls = False a risk? I notice that this was introduced in VS 2005, as some apps written under VS 2003 suffered from cross-threading bugs.
Many thanks,

Thanks for the input. I'm not sure why my original code did not work -- but you have provided me with the solution I needed. Many thanks.
Your help has saved me hundreds of hours of internet surfing.