Tips for Transitioning to Version 4
This list outlines the coding changes needed when upgrading to version 4. For more on the benefits of the new model, please see PowerTCP 4.
No more Async methods
Previous versions of PowerTCP and PowerSNMP implemented an event-driven model for asynchronous use. In addition to a synchronous method, each operation had an asynchronous "BeginXXX" method and corresponding "EndXXX" event. For example, to receive data asynchronously using the Tcp component, the developer called BeginReceive and waited for the EndReceive event to fire with data. In the meantime, other code was free to execute.
In the new model, asynchronous methods have been eliminated. Instead, the developer uses one or more synchronous methods (for example, "Receive") within a straight blocking function, and then passes a delegate referring to this function to the component's Start method. The Start method then executes the function on its own worker thread.
Marshaling data back to the UI thread
It is often necessary to pass information from a worker thread to an element on the UI thread. The new model includes Marshal functions to simplify these cross-thread operations. Each Marshal overload corresponds to an event handler that executes on the UI thread and provides access to data passed using the Marshal method.
No more "pseudo-blocking"
Methods in the new model are now true-blocking calls. In previous versions, methods were "pseudo-blocking," meaning that events could be raised while the call blocked. With the new model, the UI is blocked if a method is called from within the UI thread. The Start method should therefore be used in UI environments so that events are raised.
Some components, such as Ping, make use of child Slave objects to perform blocking operations. The parent component defines events and includes properties that apply to all slaves.
Use of IPEndPoints
Many methods in the current model include overloads that take IPEndPoint parameters, to facilitate IPv6 use. A new IPEndPoint derived class provides several overloads for easy IPEndPoint creation, including automatic hostname resolution.