tags:

views:

335

answers:

4

Hello there,

Can anybody reccomend books or other online resources for MultiThreaded Windows Forms in C# ? I am mostly interested to learn more about this topic especially in the context of a GUI application that sends messages and listens in the background for responses from the server.

Many Thanks, MK

+3  A: 

I don't know if there are any specific books on WinForms and multithreading. There are books which discuss the .NET Asynchronous Programming Model, which is used considerably in WinForms and WPF programming.

Try Programming .NET Components by Juval Louwy (OReilly Press) as well as CLR via C# by Jeffrey Richter (Microsoft Press). That ought to get you started.

kmontgom
+2  A: 

I'd second CLR via C#, but Concurrent Programming on Windows by Joe Duffy does multithreading and concurrency in much more depth if that's what you're looking for.

EDIT: Windows Forms 2.0 Programming by Chris Sells also has coverage of the topic and is a very good (and readable) general WinForms book if you dont already have one

Ruben Bartelink
+1  A: 

Bill Wagner's More Effective C#: 50 Specific Ways to Improve Your C# addresses this topic, along with many other useful ones.

Sorin Comanescu
+1  A: 

I recommend you look into retlang http://code.google.com/p/retlang/ it has changed the way I code my apps on a fundamental level. Quick and dirty example that may or may not compile that lissens to some server message string and presents it in a textbox.

using Retlang.Channels;
using Retlang.Fibers;
using Retlang.Core;
public partial class FooForm: Form 
{
    PoolFiber _WorkFiber; //backround work fiber
    FormFiber _FormFiber; //this will marshal the messages to the gui thread
    Channel<string> _ServerMessageChannel;
    bool _AbortWork = false;
    public FooForm()
    {
        InitializeComponent();
        _ServerMessageChannel= new Channel<string>();
        _WorkFiber = new PoolFiber();
        _FormFiber = new _Fiber = new FormFiber(this,new BatchAndSingleExecutor());
        _WorkFiber.Start(); //begin recive messages
        _FormFiber .Start(); //begin recive messages
        _WorkFiber.Enqueue(LissenToServer);
        _ServerMessageChannel.Subscribe(_FormFiber,(x)=>textBox1.Text = x);
    }
    private LissenToServer()
    {
         while(_AbortWork == false)
         {
            .... wait for server message
            string mgs = ServerMessage();
            _ServerMessageChannel.Publish(msg);

         }
    }
}
Marcus