0

I'm trying to develop my application extension and part of it has a variable that I want to tell if the user has an internet connection or not. I've set it up to where it's read only, but I'm trying something new and it threw a StackOverflowException. Hopefully someone can explain why and how to fix it?

[DllImport("wininet.dll")]
        private extern static bool InternetGetConnectedState(out int desc, int reserved);

        public bool InternetConnection
        {
            get
            {
                return InternetConnection;
            }

            private set
            {
                InternetConnection = false;
                int desc = 0;

                if (InternetGetConnectedState(out desc, 0))
                {
                    InternetConnection = true;
                }
            }
        }

I have no knowledge of Stack Overflow Exceptions, I don't know what causes them, how to fix them, or anything else of that nature.

Edited by lxXTaCoXxl: n/a

2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by lolafuertes
0

The problem is that the get method returns itself. You should change it to return the InternetConnectionState:

[DllImport("wininet.dll")]
        private extern static bool InternetGetConnectedState(out int desc, int reserved);
        public bool InternetConnection
        {
            get
            {
                int desc; // By default is initialized to 0.
                return InternetGetConnectedState(out desc, 0);
            }

        }

Hope this helps

Edited by lolafuertes: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.