Click here to Skip to main content
15,846,342 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:

there is 2 clases 1 is form1 and 2nd i make called connection now i make connection in my class and i open connection by using and thn i called function f1 which in form1 class now at thr i show msg box now i want to go bak to my connection class and in that particular line conn.close how i do this
Updated 19-Nov-11 23:23pm
DaveAuld 20-Nov-11 4:17am    
Not very clear what you are up to. You can look to use events and public accessors if you want to 'communicate' between classes...

1 solution

I'm not sure why you think that would be a good idea.
The only reason I can think of that you would want to do this, is if the method in form1 is going to display information from the connection - which means there are a couple of potential problems here:
If your connection is not using the same thread as the form1 instance, then any attempt to display information is going to fail, unless you use Invoke.
If your method relies on actually communicating via the connection, then it may not complete it's processing immediately - if it uses any blocking calls, then it will freeze the thread from which you are calling it - so if that comes from a different forms UI (a button click or similar, say) then it will lock that form up until it returns.
If it doesn't use blocking, then it will return - and you will close the connection - before processing if complete.

What are you trying to achieve, that you think this is a good solution? There may be a better, easier, way to do it.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900