Sign in to follow this  

C# - using object variables

This topic is 4309 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Does anyone know how to access the "original" members and/or functions of an object variable (not an Object variable) in C#? The reason I must know is because I'm using an IOCP library for C#, and when I dispatch objects, like sockets for example, they are returned as object variables to the different threads that are listening to the IOCP. The problem I'm having is that I can't access the methods and functions of a Socket type by way of an object variable, meaning that I can't write to a client unless I figure out how to access the Socket functions and members by way of an object variable. Example ======= BeginAccept() callback function that dispatches a socket to the IOCP:
        private void AcceptCallback(IAsyncResult ar)
        {
            Socket Listener = (Socket)ar.AsyncState;
            Socket Handler = Listener.EndAccept(ar);
            MIOCP.Dispatch(Handler);
        }
HandleIOCPData() function that is run by the IOCP worker threads:
        public void HandleIOCPData()
        {
            //This is the minimum code that should be in here.
            IOCPHandle hIOCP = MIOCP.Register();
            while (true)
            {
                try
                {
                    object obj = hIOCP.Wait();
                    // Process the object
                }
                catch (ManagedIOCPException e)
                {
                    break;
                }
                catch (Exception e)
                {
                    break;
                }
            }
        }
¨ As you can see, the dispatched socket is returned as an object variable. I need to know how to treat the object as a socket. Any ideas?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
((Socket)obj).Blah() will work. The . is evaluated before the cast.

Share this post


Link to post
Share on other sites

This topic is 4309 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this