|
-
February 2nd, 2009, 03:01 PM
#11
Re: Socket Blocking Read TimeOut!
 Originally Posted by EmbeddedC
The clue is, I want to use it in a GUI application. Using async BeginRead/EndRead still makes it not friendly as a class for a GUI. Because I have to call Mainthread.InvokeRequired to post the mainthread a message that some data has been received. While using backgroundworker class, we don't have that problem and the class much better to use for other programmers.
Yes and no.
The 'yes' part:
BackgroundWorker *slightly* simplifies how async operations can be safely used in a winforms application. All it does is call Mainthread.Invoke () for you when you raise the ProgressChanged and RunWorkerComplete events so that these events end up on the main loop. That's the only 'magic' it has.
The 'no' part:
You most definitely do *not* want to use 1 thread per socket in an application which makes heavy use of sockets. If you're only making a few connections (~5) then it's fine. If you're making 300 connections, it'd be horrible 
In either case, you can still use the async methods. There's no issue with using them as part of your background worker. Things will be pretty much exactly the same as what you have now, except that you'll be using BeginRead and EndRead instead of just "Read". If you're using the background worker correctly, things will work just fine.
www.monotorrent.com For all your .NET bittorrent needs
NOTE: My code snippets are just snippets. They demonstrate an idea which can be adapted by you to solve your problem. They are not 100% complete and fully functional solutions equipped with error handling.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|