Hi all
I've written a asynchronous socket client class, but i've found that in order to consume it I have to use events, and cannot simply for example
SocketClient client = new SocketClient(110, "some.server.com")
client.Connect()
client.SendData("Hello World")
Instead I have to wait for the async method to raise a Connected event, and call client.SendData from there, for complex chains of operations this because a nightmare chain of events
I tried using a manual reset event as on the microsoft example to halt the return of my Connect method until the asynchronous callback had completed, but this blocks the UI
Microsofts example:
http://msdn.microsoft.com/library/de...ketexample.asp
blocks the UI as far as I can tell when consuming the class. Although it says it doesnt
So my question is, how can I use my asynchronous socket client like above, intead of having event chains? I believe using ManualResetEvents is the way except I can't make it work without blocking, Unless I do the following
SocketClient client = new SocketClient(110, "some.server.com")
Thread connectThread = new Thread(new ThreadStart(client.Connect))
connectThread.Start()
Is that the way that I must handle this? if so how do I dispose of the thread properly when it has completed? This poses the problem of not knowing when the thread has completed its job
Using synchronous sockets isn't really an option because its for a POP3 Client, and there will be alot of receiving large messages etc
Id appreciate any ideas on this,
Thanks
Matt.