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
sub1()
sub2()
sub3()
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...)
picturebox.show()
connect to database
run large "SELECT INTO" command
picturebox.hide()
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?
(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
sub1()
sub2()
sub3()
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...)
picturebox.show()
connect to database
run large "SELECT INTO" command
picturebox.hide()
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?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
ASKER
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 CheckForIllegalCrossThread
Many thanks,
James