Subscribing to Session Events | Table of Content | Accepting FIX Session Without a Prior Creation of Session Object |
Updating GUI Controls on Session Event |
Session events are fired from the thread of execution of the OnixS .NET Framework FIX Engine. In order to safely update GUI Controls, it is necessary to use the Control.BeginInvoke method. Otherwise, an application may hang.
The following example demonstrates how to properly update GUI controls from session event handlers.
delegate void UpdateSessionStateDelegate(string state); void UpdateSessionState(string state) { statusBar.Panels[0].Text = state; } void OnStateChange(Object sender, StateChangeEventArgs e) { statusBar.BeginInvoke( new UpdateSessionStateDelegate(UpdateSessionState), new object[] {e.NewState.ToString()}); }
Dim formStatusBar As StatusBar = New StatusBar Delegate Sub UpdateSessionStateDelegate(ByVal state As String) Sub UpdateSessionState(ByVal state As String) formStatusBar.Panels.Item(0).Text = state End Sub Sub OnStateChange(ByVal sender As Object, ByVal e As StateChangeEventArgs) formStatusBar.BeginInvoke( _ New UpdateSessionStateDelegate(AddressOf Me.UpdateSessionState), _ New Object() {e.NewState.ToString()}) End Sub