|
-
Jan 8th, 2008, 01:01 PM
#1
Thread Starter
Hyperactive Member
[2005] threading problem
Oh boy a threading problem! I bet you guys never get any of those lol. I've got a sub that does some database stuff but mainly you need to know this part of it:
Code:
m_Connection.Open()
count = cmd.ExecuteNonQuery()
m_Connection.Close()
So what's apparently happening according to the error is back in the main code I call the thread attached to this sub and it gets all the way through my loop and back to telling the thread again. Then it crashes saying that the connection's state is already open so it can't be opened. So I thought it's running a second version of the sub/thread but when I walk through it in debug, it gets to the nonQueryThread.Start() command for the second time and says it can't start the thread because it's already running. So I'm not really sure why it didn't crash on that before. Does it just not start the thread and keep going without crashing and whatever happens, oh well?
Anyway, later in my program I need to do the same thing but pretty much the next line after the start thread command it needs to do something with the resulting datatable of that thread to be there so how can I get my program to wait for that thread to get done before doing anything else?
And if you recall, I'm putting all the database stuff in seperate subs/threads because it's screwing with my progress label refreshing on the form and causing it to not refresh if I do pretty much anything. If I tell my program to wait for that thread to finish would that cause the same problem?
Oh and if anyone knows how I can do this other idea, then forget all that crap above. If I just put the form refresh sub in a seperate thread I think that would in theory, keep the form from freezing up. But of course I can't access the form from inside another thread because of the big sharing permissions problem thing that I have no idea how to get around. So if anyone knows how to just make sure the form's refresh sub actually refreshes it, that'd help too
Last edited by Desolator144; Jan 8th, 2008 at 01:16 PM.
I tried to end process on Visual Studio 2005
but PETA stopped me saying it's smart enough
to be a living creature 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|