koumides
koumides

Reputation: 2504

MultiThreaded WinForms in C#

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

Upvotes: 1

Views: 1224

Answers (4)

Ruben Bartelink
Ruben Bartelink

Reputation: 61795

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 don't already have one

Upvotes: 2

Marcus
Marcus

Reputation: 31

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);

         }
    }
}

Upvotes: 3

Sorin Comanescu
Sorin Comanescu

Reputation: 4867

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

Upvotes: 1

kmontgom
kmontgom

Reputation: 1429

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.

Upvotes: 3

Related Questions