Question about SynchronizingObject

Apr 19, 2010 at 11:14 AM

I am doing an application to establish connections through several GPRS modems connected to the same Windows Machine.  For this purpose, I have a different thread taking care of each connection.

 

I am having problems with the Disconnected event from  RasConnectionWatcher. Although I am providing the connection handler to the RasConnectionWatcher, the disconnected event is being triggered in each thread instead of being triggered in the specific one that is running.

 

I am not using windows forms, so should I use SynchronizingObject?  how can I use it?

 

Thanks

Apr 19, 2010 at 11:17 AM

Sorry I forgot: should I use SynchronizingObject for the DialAsync method I am using in each thread as well?

Coordinator
Apr 19, 2010 at 2:41 PM

The RasConnectionWatcher receives notifications for all connections on the machine unless you instruct it to monitor for a single connection handle. If you are creating multiple RasConnectionWatcher objects for each thread, you should probably set the Handle property on the watcher to the handle returned by the DialAsync method from the RasDialer. Also, this information was in the SDK help file under the remarks of the RasConnectionWatcher.

The SynchronizingObject is only required if you need to marshal events back to a specific thread. Typically this is only need if you're using a user interface, applications like Windows services do not require any thread marshalling. Whether you need it to use it depends upon your applications needs, I can't say yes you always need it.