473,396 Members | 1,927 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

C# Win Forms GUI locks up with Asynch Socket Callback / WinForms.Delegate

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.Tex t,
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.ConnResultDel egate,
new Object[] { _IPAddr _PortNum,
"Connected Successfully!" } );
OR

_ParentFormObj.BeginInvoke(_ParentFormObj.ConnResu ltDelegate,
new Object[] { _IPAddr,
_PortNum, "Connected Successfully!" } );

}
}

i omitted exception handling and other to include to be as brief as
possible.

thanks so much, dave

Aug 15 '07 #1
3 5190
Dave wrote:
[...]
i omitted exception handling and other to include to be as brief as
possible.
You omitted so much code, it's impossible to say for sure what's going on.

However, your symptom describes a classic deadlock situation, so I
suspect that your AttemptConnection method or the StartButton_Click
method has some sort of "wait for completed connection" logic in it.
This prevents the main UI thread from ever being in a position to
service the invoked delegate.

Normally, using BeginInvoke would work around an issue like this, which
suggests you also have something waiting on the BeginInvoke() somehow.
Again, lacking complete code, it's hard to say.

Pete
Aug 15 '07 #2
On Aug 15, 11:12 am, Peter Duniho <NpOeStPe...@NnOwSlPiAnMk.com>
wrote:
Dave wrote:
[...]
i omitted exception handling and other to include to be as brief as
possible.

You omitted so much code, it's impossible to say for sure what's going on.

However, your symptom describes a classic deadlock situation, so I
suspect that your AttemptConnection method or the StartButton_Click
method has some sort of "wait for completed connection" logic in it.
This prevents the main UI thread from ever being in a position to
service the invoked delegate.

Normally, using BeginInvoke would work around an issue like this, which
suggests you also have something waiting on the BeginInvoke() somehow.
Again, lacking complete code, it's hard to say.

Pete
hmm you're right on both fronts. no nailed my issue and i did omit
too much code.

good job and thanks, dave

Aug 15 '07 #3
On Aug 15, 11:25 am, Dave <djohanns...@gmail.comwrote:
On Aug 15, 11:12 am, Peter Duniho <NpOeStPe...@NnOwSlPiAnMk.com>
wrote:


Dave wrote:
[...]
i omitted exception handling and other to include to be as brief as
possible.
You omitted so much code, it's impossible to say for sure what's going on.
However, your symptom describes a classic deadlock situation, so I
suspect that your AttemptConnection method or the StartButton_Click
method has some sort of "wait for completed connection" logic in it.
This prevents the main UI thread from ever being in a position to
service the invoked delegate.
Normally, using BeginInvoke would work around an issue like this, which
suggests you also have something waiting on the BeginInvoke() somehow.
Again, lacking complete code, it's hard to say.
Pete

hmm you're right on both fronts. no nailed my issue and i did omit
too much code.

good job and thanks, dave- Hide quoted text -

- Show quoted text -
good grief i typed to fast there. that should have been "you nailed
my issue and i did omit too much code".

Aug 15 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Cybertof | last post by:
Hello, I'm inserting a new row in a Access database containing an "AutoIncrement" column. The autoincrement value is set by the database once the update occurs. The only way to get this value...
1
by: Barry Anderberg | last post by:
I am using asynch sockets and so I call BeginReceive and then in my callback function I have certain events that would cause me to want to throw an exception. The problem of course is that the...
22
by: Jeff Louie | last post by:
Well I wonder if my old brain can handle threading. Dose this code look reasonable. Regards, Jeff using System; using System.Diagnostics; using System.IO; using System.Threading;
2
by: Dion Heskett | last post by:
Hi I get a InvalidOperationException message when I click button2 at this line of code textBox1.Text = whoIs1.EndLookup( asyncResult ); Should I now be implementing the BackgroundWorker Class...
20
by: David Levine | last post by:
I ran into a problem this morning with event accessor methods that appears to be a bug in C# and I am wondering if this a known issue. public event SomeDelegateSignature fooEvent; public event...
1
by: Sean | last post by:
I am looking at using delegates to perform an asynchronous call. There will be a callback invoked at the end of the call. The client thread will wait on the WaitHandle from IAsyncResult (which is...
2
by: darthghandi | last post by:
I am trying to pass a socket object when an event is signaled. I have successfully bound to a network interface and listened on a port for incoming connection. I have also been able to accept...
10
by: David | last post by:
I have googled to no avail on getting specifically what I'm looking for. I have found plenty of full blown apps that implement some type of file transfer but what I'm specifcally looking for is an...
4
by: =?iso-8859-1?B?S2VyZW0gR/xtcvxrY/w=?= | last post by:
Hi, i have a main thread an another worker thread. The main Thread creates another thread and waits for the threads signal to continue the main thread. Everything works inside a ModalDialog and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.