c# backgroundworker for socket application -


I'm working on a C # window application This app is primarily related to socket.

I have a class called TCPPS, which manages all socket-level functionality, receives data, and so on. The controller class calls this TCPPSset. In addition, this file does all other work of logging data and updates the GUI. I thought it would be good to have this controller in the background controller, to make sure that he is responsible all the time. First of all, is there a good idea to do this?

As I am trying to do this, I have to face a problem about the progressive handler for the background player. I want to be able to display the connection status (type: string) in the text field and the data received / received by the application (type: byte []) in the rich textbox as the controller can only send data to Guateta through progress Is the changing event, how can I pass different types of data (string / byte []) to Gui?

If you decide to run the controller on a different thread other than the UI thread, Thread must be hooked to an administrator by changing the progress on a method handler from an administrator. Once you have done this, you have to modify the data from the process to be maurshalled on the UI thread. Below is an example of how to do marshal.

  Private Object _lock = New Object (); // should have a private zeros in the scope of the Dispalymessage (byte [] bytes) {if (This.InvokeRequired) {Lock (_lock) {EventHandler D = New EventHandler (DispalyMessage); This.Invoke (D, new object [] (bytes)); Return; }} And {// bytes data have been martialized to the Yuri Thread from the thread of the controller category and can be used to populate a member of the UI. }}  

Additionally you may need to modify your controller and add different events, which can return something other than one type: byte [] you only Taking advantage of the class that is part of the net framework or you can take advantage of the representative class directly.

Enjoy!


Comments

Popular posts from this blog

Eclipse CDT variable colors in editor -

AJAX doesn't send POST query -

wpf - Custom Message Box Advice -