Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old October 23rd, 2008, 10:27 PM
Authorized User
Join Date: Aug 2008
Posts: 38
Thanks: 1
Thanked 0 Times in 0 Posts
Default problem retrieving data processed by class library

Pls help! how am i going to update a form's listbox with data handled and stored by a class library ( the messages are from a connected socket)?
I want this listbox to diplay chat messages.

class X (class library code)

properties: ipadd,port,isconnected...etc
    Connect() and ConnectCallback //will establish connection to the socket using BeginConnect and EndConnect
    WaitForData and OnDataReceived(Callback) //will received the messages using BeginReceive and EndReceive

        public void WaitForData()
            recieveCallback = new AsyncCallback(onDataReceived);
            StateObject socket = new StateObject();
            socket.workSocket = mainClientSocket;
            result = mainClientSocket.BeginReceive(socket.buffer, 0, socket.buffer.Length, SocketFlags.None, recieveCallback, socket);

        private void onDataReceived(IAsyncResult result)
            StateObject socket = (StateObject)result.AsyncState;
            if (mainClientSocket.Connected)

                bytesRcvd = socket.workSocket.EndReceive(result);
                ReadXML(bytesReceived, socket); //method that will parse the message

        private void ReadXML(int bytes, StateObject socket)
          Once data is parsed , it will be stored in SenderMessageList ///(List<string>)
            SenderMessageQueue(Sender + ": " + Message);
        private void SenderMessageQueue(String message, String socketID)

        public String getSenderMessage //// I will call this property in a form to display //// the stored message
                return SenderMessageList[SenderMessageList.Count - 1];

Form // will use the library

namespace WindowsFormsApplication4
            using X;
            x= new X.ClientSocket();
            IntPtr handle = this.Handle;
            x.IPadd = "";
            x.Port = 8222;

            ThreadStart threadStarter = new ThreadStart(ReceiveMessages);
            myThread = new Thread(threadStarter);
            myThread.IsBackground = true;

        private void ReceiveMessages()

            while (x.bytesReceived != 0)
                 listBox1.Invoke(new UpdateTextCallback(this.Update_listBox1), new object[] { a });

            listBox1.Invoke(new UpdateTextCallback(this.Update_listBox1), new object[] { x.getSenderMessage });

        private void Update_listBox1(String text)

        private void ButtonSend_click{

When i move the listbox.invoke in ButtonSend, i can get the stored message..But what i want to do is automate the receiving of data..Sending has no problem cause it's working...I am by the way creating a chat program..i want to see all the messages coming in...Thanks.

Similar Threads
Thread Thread Starter Forum Replies Last Post
use of class library Theone84 C# 1 July 26th, 2008 02:19 AM
Problem with returning value from class library labby C# 1 September 11th, 2006 08:50 AM
problem Extracting Data using HTML Object Library method VB How-To 0 May 12th, 2006 02:52 AM
Regarding Class Library (.dll) from class file manish.sharma04 BOOK: Wrox's ASP.NET 2.0 Visual Web Developer 2005 Express Edition Starter ISBN: 978-0-7645-8807-5 1 March 3rd, 2006 07:32 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.