D
Danny Tuppeny
Hi All,
I've written a console app, which sends and recieves data across a
NetworkStream and displays output to the console. All is great.
I'm now modifying it to be a windows app, but the thing blocks while waiting
to recieve data. So, I want to run it in a thread. However, the object
that's running my events fires events, and these all need to update the UI.
What's the best way of doing this? Should I call BeginInvoke from inside my
event handlers, or should my object raise these events on the main thread
anyway?
Most of my threading experience is using the BackgroundWorker class, but
this doesn't really fit my needs (using ProgressUpdate owuld be a hack ;o))
Below is my main class code. pokerServer.Go() needs to be run inside a
thread, but the event needs to write to my listbox. Any recommendations on
the best way?
Thanks,
(note, this is .net2)
namespace DTuppeny.PokerBot
{
public partial class TuppoBot : Form
{
PokiPokerServer pokerServer;
public TuppoBot()
{
InitializeComponent();
pokerServer = new PokiPokerServer();
pokerServer.Log += new LogHandler(pokerServer_Log);
}
void pokerServer_Log(string s)
{
listLog.Items.Add(s);
}
private void btnJoin_Click(object sender, EventArgs e)
{
pokerServer.Go();
}
}
}
I've written a console app, which sends and recieves data across a
NetworkStream and displays output to the console. All is great.
I'm now modifying it to be a windows app, but the thing blocks while waiting
to recieve data. So, I want to run it in a thread. However, the object
that's running my events fires events, and these all need to update the UI.
What's the best way of doing this? Should I call BeginInvoke from inside my
event handlers, or should my object raise these events on the main thread
anyway?
Most of my threading experience is using the BackgroundWorker class, but
this doesn't really fit my needs (using ProgressUpdate owuld be a hack ;o))
Below is my main class code. pokerServer.Go() needs to be run inside a
thread, but the event needs to write to my listbox. Any recommendations on
the best way?
Thanks,
(note, this is .net2)
namespace DTuppeny.PokerBot
{
public partial class TuppoBot : Form
{
PokiPokerServer pokerServer;
public TuppoBot()
{
InitializeComponent();
pokerServer = new PokiPokerServer();
pokerServer.Log += new LogHandler(pokerServer_Log);
}
void pokerServer_Log(string s)
{
listLog.Items.Add(s);
}
private void btnJoin_Click(object sender, EventArgs e)
{
pokerServer.Go();
}
}
}