D
Dave
I wrote a simple Asynchronous Socket client that receives OnConnect
notifications and attempts to report this back to the win forms app.
as the notification method is on another thread i'm using
winforms.Invoke or BeginInvoke but the GUI locks up - seemingly just
after entering ConnectResultInvoked().
i thought this was to be pretty straightforward, but i'm stumped so
far. does anyone know what could be the problem??
here's a skeleton of the code:
public partial class WLClientInfoForm : Form
{
public delegate void ConnectResultDelegate(string IPAddr, int
PortNum, string ConnectionResult);
public ConnectResultDelegate ConnResultDelegate;
AsynchClient _SockClient;
public WLClientInfoForm()
{
ConnResultDelegate = new
ConnectResultDelegate(ConnectResultInvoked);
}
public void ConnectResultInvoked(string IPAddr, int PortNum,
string ConnectionResult)
{
ListViewItem TSItem =
ConnectResultsListView.Items.Add(IPAddr);
TSItem.SubItems.Add(PortNum.ToString());
TSItem.SubItems.Add(ConnectionResult);
}
private void StartButton_Click(object sender, EventArgs e)
{
_SockClient = new AsynchClient(this);
_SockClient.AttemptConnection(IPAddressTextBox.Text,
PortNumberTextBox.Text);
}
.....
}
class AsynchClient
{
WLClientInfoForm _ParentFormObj;
public AsynchClient(WLClientInfoForm ParentFormObj)
{
_ParentFormObj = ParentFormObj;
}
public bool AttemptConnection(string IPAddr, string PortNum)
{
....
client.BeginConnect(remoteEP,
new
AsyncCallback(ConnectCallback), client);
.....
}
private void ConnectCallback(IAsyncResult ar)
{
...
client.EndConnect(ar);
_ParentFormObj.Invoke(_ParentFormObj.ConnResultDelegate,
new Object[] { _IPAddr _PortNum,
"Connected Successfully!" } );
OR
_ParentFormObj.BeginInvoke(_ParentFormObj.ConnResultDelegate,
new Object[] { _IPAddr,
_PortNum, "Connected Successfully!" } );
}
}
i omitted exception handling and other to include to be as brief as
possible.
thanks so much, dave
notifications and attempts to report this back to the win forms app.
as the notification method is on another thread i'm using
winforms.Invoke or BeginInvoke but the GUI locks up - seemingly just
after entering ConnectResultInvoked().
i thought this was to be pretty straightforward, but i'm stumped so
far. does anyone know what could be the problem??
here's a skeleton of the code:
public partial class WLClientInfoForm : Form
{
public delegate void ConnectResultDelegate(string IPAddr, int
PortNum, string ConnectionResult);
public ConnectResultDelegate ConnResultDelegate;
AsynchClient _SockClient;
public WLClientInfoForm()
{
ConnResultDelegate = new
ConnectResultDelegate(ConnectResultInvoked);
}
public void ConnectResultInvoked(string IPAddr, int PortNum,
string ConnectionResult)
{
ListViewItem TSItem =
ConnectResultsListView.Items.Add(IPAddr);
TSItem.SubItems.Add(PortNum.ToString());
TSItem.SubItems.Add(ConnectionResult);
}
private void StartButton_Click(object sender, EventArgs e)
{
_SockClient = new AsynchClient(this);
_SockClient.AttemptConnection(IPAddressTextBox.Text,
PortNumberTextBox.Text);
}
.....
}
class AsynchClient
{
WLClientInfoForm _ParentFormObj;
public AsynchClient(WLClientInfoForm ParentFormObj)
{
_ParentFormObj = ParentFormObj;
}
public bool AttemptConnection(string IPAddr, string PortNum)
{
....
client.BeginConnect(remoteEP,
new
AsyncCallback(ConnectCallback), client);
.....
}
private void ConnectCallback(IAsyncResult ar)
{
...
client.EndConnect(ar);
_ParentFormObj.Invoke(_ParentFormObj.ConnResultDelegate,
new Object[] { _IPAddr _PortNum,
"Connected Successfully!" } );
OR
_ParentFormObj.BeginInvoke(_ParentFormObj.ConnResultDelegate,
new Object[] { _IPAddr,
_PortNum, "Connected Successfully!" } );
}
}
i omitted exception handling and other to include to be as brief as
possible.
thanks so much, dave