Click here to Skip to main content
16,005,037 members
Home / Discussions / C#
   

C#

 
Questionabout c# com call from c++ Pin
JXW300019-Nov-06 15:07
JXW300019-Nov-06 15:07 
Questiona Desktop Dashboard Using DirectX!!! Pin
homer simpsom19-Nov-06 12:25
homer simpsom19-Nov-06 12:25 
AnswerRe: a Desktop Dashboard Using DirectX!!! Pin
Christian Graus19-Nov-06 13:29
protectorChristian Graus19-Nov-06 13:29 
GeneralRe: a Desktop Dashboard Using DirectX!!! Pin
homer simpsom20-Nov-06 9:34
homer simpsom20-Nov-06 9:34 
GeneralRe: a Desktop Dashboard Using DirectX!!! Pin
Christian Graus20-Nov-06 9:43
protectorChristian Graus20-Nov-06 9:43 
AnswerRe: a Desktop Dashboard Using DirectX!!! Pin
ednrgc20-Nov-06 3:44
ednrgc20-Nov-06 3:44 
QuestionHow to reconnect socket Pin
engsrini19-Nov-06 9:24
engsrini19-Nov-06 9:24 
AnswerRe: How to reconnect socket Pin
mertkan6519-Nov-06 22:44
mertkan6519-Nov-06 22:44 
The recommended way to do this with V2.0 of the framework is to use the System.Net.NetworkInformation namespace.. This sample should get you started:


public class NetInfoTest<br />
<br />
        {<br />
            public static void Main()<br />
<br />
            {<br />
                try<br />
<br />
                {<br />
                    DumpIPAddresses();<br />
<br />
                    NetworkChange.NetworkAvailabilityChanged += OnNetworkAvailabilityChanged;<br />
<br />
                    NetworkChange.NetworkAddressChanged += OnNetworkAddressChanged;<br />
<br />
                    Console.ReadLine();<br />
                }<br />
<br />
                catch (Exception e)<br />
<br />
                {<br />
                    Console.WriteLine(e);<br />
                }<br />
<br />
                finally<br />
<br />
                {<br />
                    Console.ForegroundColor = ConsoleColor.Green;<br />
<br />
                    Console.BackgroundColor = ConsoleColor.Black;<br />
                }<br />
            }<br />
<br />
<br />
            public static void OnNetworkAvailabilityChanged(object sender, NetworkAvailabilityEventArgs e)<br />
<br />
            {<br />
                if (e.IsAvailable)<br />
<br />
                {<br />
                    Console.ForegroundColor = ConsoleColor.Green;<br />
<br />
                    Console.WriteLine("Network Available");<br />
                }<br />
<br />
                else<br />
<br />
                {<br />
                    Console.ForegroundColor = ConsoleColor.Red;<br />
<br />
                    Console.WriteLine("Network *NOT* Available");<br />
                }<br />
            }<br />
<br />
            public static void OnNetworkAddressChanged(object sender, EventArgs e)<br />
<br />
            {<br />
                Console.ForegroundColor = ConsoleColor.Red;<br />
<br />
                Console.BackgroundColor = ConsoleColor.Yellow;<br />
<br />
                Console.WriteLine("Address change event at {0}", DateTime.Now.ToString());<br />
<br />
                Console.ForegroundColor = ConsoleColor.Green;<br />
<br />
                Console.BackgroundColor = ConsoleColor.Black;<br />
<br />
                DumpIPAddresses();<br />
            }<br />
<br />
            public static void DumpIPAddresses()<br />
<br />
            {<br />
//1. Get All Network Interfaces<br />
<br />
                NetworkInterface[] NetworkInterfaces = NetworkInterface.GetAllNetworkInterfaces();<br />
<br />
//2. Loop over the interfaces<br />
<br />
                foreach (NetworkInterface NI in NetworkInterfaces)<br />
<br />
                {<br />
//3. Select Ethernet Interface<br />
<br />
                    if (NI.NetworkInterfaceType == NetworkInterfaceType.Ethernet)<br />
<br />
                    {<br />
                        Console.WriteLine(Environment.NewLine);<br />
<br />
                        Console.WriteLine(Environment.NewLine);<br />
<br />
//4. Print Name and description<br />
<br />
                        Console.WriteLine(NI.Name + " " + NI.Description);<br />
<br />
                        Console.WriteLine("-------------------------------------------------");<br />
<br />
//5. Get the IP Interface properties<br />
<br />
                        IPInterfaceProperties IPProps = NI.GetIPProperties();<br />
<br />
//6. Get all the Unicast Addresses<br />
<br />
                        UnicastIPAddressInformationCollection UnicastAddresses = IPProps.UnicastAddresses;<br />
<br />
                        foreach (UnicastIPAddressInformation uaddr in UnicastAddresses)<br />
<br />
                        {<br />
//7. Print ONLY IPv4 Addresses<br />
<br />
                            if (uaddr.Address.AddressFamily == AddressFamily.InterNetwork)<br />
<br />
                                Console.WriteLine("\t" + uaddr.Address.ToString());<br />
                        }<br />
                    }<br />
                }<br />
            }<br />
        }<br />


Keep in mind availability here is based on the state of the network adapter. This does not tell you the reach of your connection (ie. connected to the internet, a managed network, etc)

You can use "NetworkAvailabilityChanged" and "NetworkAddressChanged" events, for reconnect operation.

Thanks Mike Flasko for code example;)
QuestionChanging build paths? Pin
Lord Kixdemp19-Nov-06 9:14
Lord Kixdemp19-Nov-06 9:14 
AnswerRe: Changing build paths? Pin
Christian Graus19-Nov-06 9:31
protectorChristian Graus19-Nov-06 9:31 
GeneralRe: Changing build paths? Pin
Paul Conrad19-Nov-06 10:41
professionalPaul Conrad19-Nov-06 10:41 
GeneralRe: Changing build paths? Pin
Lord Kixdemp19-Nov-06 13:12
Lord Kixdemp19-Nov-06 13:12 
GeneralRe: Changing build paths? Pin
Christian Graus19-Nov-06 13:32
protectorChristian Graus19-Nov-06 13:32 
GeneralRe: Changing build paths? Pin
Lord Kixdemp21-Nov-06 10:51
Lord Kixdemp21-Nov-06 10:51 
AnswerRe: Changing build paths? Pin
Paul Conrad19-Nov-06 10:42
professionalPaul Conrad19-Nov-06 10:42 
QuestionRGB value of picture then convert to HSI Pin
ullasthelegend19-Nov-06 8:32
ullasthelegend19-Nov-06 8:32 
AnswerRe: RGB value of picture then convert to HSI Pin
Ed.Poore19-Nov-06 8:41
Ed.Poore19-Nov-06 8:41 
AnswerRe: RGB value of picture then convert to HSI Pin
Christian Graus19-Nov-06 9:32
protectorChristian Graus19-Nov-06 9:32 
GeneralRe: RGB value of picture then convert to HSI Pin
J. Dunlap19-Nov-06 20:42
J. Dunlap19-Nov-06 20:42 
GeneralRe: RGB value of picture then convert to HSI Pin
legendu21-Nov-06 23:23
legendu21-Nov-06 23:23 
QuestionMIDI to Guitar Tablature Pin
Vertyg019-Nov-06 7:31
Vertyg019-Nov-06 7:31 
AnswerRe: MIDI to Guitar Tablature Pin
Christian Graus19-Nov-06 9:35
protectorChristian Graus19-Nov-06 9:35 
GeneralRe: MIDI to Guitar Tablature Pin
ejuanpp19-Nov-06 22:50
ejuanpp19-Nov-06 22:50 
GeneralRe: MIDI to Guitar Tablature Pin
Christian Graus19-Nov-06 23:04
protectorChristian Graus19-Nov-06 23:04 
GeneralRe: MIDI to Guitar Tablature Pin
ejuanpp19-Nov-06 23:23
ejuanpp19-Nov-06 23:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.