stop or kill connection attempt after specified period of time

andresleon

Member
Joined
Jun 22, 2005
Messages
9
Programming Experience
1-3
hi,
i am trying to connect to a remote machine to find out if anyone's logged in to it using wmi's ManagementObjectSearcher object. I am successful in establishing the connection and getting the information i need from machines that are up and running. However, when i try to access a machine that is off or not accessible, the get command runs for almost 30 seconds and then tells me that the RPC server is not available. This is expcted and understandable.
What i would like to figure out is how to automatically kill the connection attempt after a determined amount of time. For example, i would like to try to connect, but if it has been more than 5 seconds, then the conection should fail and the program should move on.

Can someone provide me with some information as to how to do this?

Thank you!
 
kulrom,
thanks for your help... again!! :)

although i am planning to switch my application into a service in the future, it currently works as a desktop app. I am not sure what you mean by creating a windows service when my app is the one trying to make the connection. can you provide a small example of what you mean?

Thanks!
 
Well, you could essentially develop a windows service with the same ease as you'd develop a windows application.
In your case you could make it to work in background ... just set up the timer as your service be able to check (every 15 seconds for instance) the another machine is OFF or ON

Cheers ;)
 
Kulrom,
I followed your advice and converted my app to a service. After a bit of struggling i got it working as i wanted. Thank you very much for your help on this!

my next challenge is memory. I have noticed that my app is now using more memory than it used to as a windows app. In fact, i'm pretty sure i have a memory leak somewhere. Do you know how i can find where in my code i may be leaking memory? Thanks again!
 
Well, it is not usual that Win Services are using more memory than commom Win apps.
Btw, it could be caused by many different things, and from this distance i cannot tell you much. However be sure that you have put "nothing" to every object there.

Here is a link that you may find useful:
Production Debugging for .NET Framework Applications
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnbda/html/dbgch02.asp


Cheers ;)
 
Btw, maybe you should use connection pooling. Actually it may be the main reason (bug) for memory leaking (connection). If we know that you are trying all the time to connect to a remote machine to find out if machine is off or on then we can easily suspect connection.
If you want to try the pooling:
The main benefit of pooling is of course performance. It enables an application to use a connection from a pool of connections that do not need to be re-established for each use (Ideal for your service). Once a connection has been created and placed in a pool, an application can reuse that connection without performing the complete connection process.

However, in this way you can save a lot of memory ... give it a try


Cheers ;)
 
Back
Top