Y
Yehia A.Salam
Hello,
I am building a network application that make use of .Net Sockets, I created
a class that works like a server and fires an event when anything arrives at
the server, however I ran into some problems because of the WPF threading
model, my code is like:
//*******************************************
public Window1(){ ...
sConnection = new myserver();
sConnection.DateReceived += new
myserver.DataReceivedHandler(OnServerDataReceived);
sConnection.StartServer();
}
private void OnServerDataReceived(MessageText Re) {
Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal,
new myserver.DataReceivedHandler(this.ServerDataReceived),Re);
}
private void ServerDataReceived(MessageText Re) {
txtconsole.Text = txtconsole.Text + Re.name + ": " + Re.content;
}
//**********************************************
the code runs correctly but I am not satisfied with the structure, I don't
like that I must have at least two methods for modifying anything in the UI,
is there a better structure to do this, like putting BeginInvoke in myServer
Class for example and just assign the ServerDataReceived event in Window1
class like I would normally do in Windows Forms.
Thanks
Yehia A.Salam
I am building a network application that make use of .Net Sockets, I created
a class that works like a server and fires an event when anything arrives at
the server, however I ran into some problems because of the WPF threading
model, my code is like:
//*******************************************
public Window1(){ ...
sConnection = new myserver();
sConnection.DateReceived += new
myserver.DataReceivedHandler(OnServerDataReceived);
sConnection.StartServer();
}
private void OnServerDataReceived(MessageText Re) {
Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal,
new myserver.DataReceivedHandler(this.ServerDataReceived),Re);
}
private void ServerDataReceived(MessageText Re) {
txtconsole.Text = txtconsole.Text + Re.name + ": " + Re.content;
}
//**********************************************
the code runs correctly but I am not satisfied with the structure, I don't
like that I must have at least two methods for modifying anything in the UI,
is there a better structure to do this, like putting BeginInvoke in myServer
Class for example and just assign the ServerDataReceived event in Window1
class like I would normally do in Windows Forms.
Thanks
Yehia A.Salam