/// <summary> /// Click handler for the getIpConfig button. /// </summary> /// <param name="sender">The caller of this method.</param> /// <param name="e">The arguments associated with this event.</param> private void GetIPConfig_Click(object sender, RoutedEventArgs e) { this.ClearOutput(); this.EnableConnectionControls(false); this.EnableDeviceControls(false); StringBuilder sb = new StringBuilder(); Task getTask = new Task( async() => { sb.Append(this.MarshalGetCommandOutput()); sb.AppendLine("Getting IP configuration..."); this.MarshalUpdateCommandOutput(sb.ToString()); try { IpConfiguration ipconfig = await portal.GetIpConfigAsync(); foreach (NetworkAdapterInfo adapterInfo in ipconfig.Adapters) { sb.Append(" "); sb.AppendLine(adapterInfo.Description); sb.Append(" MAC address :"); sb.AppendLine(adapterInfo.MacAddress); foreach (IpAddressInfo address in adapterInfo.IpAddresses) { sb.Append(" IP address :"); sb.AppendLine(address.Address); } sb.Append(" DHCP address :"); sb.AppendLine(adapterInfo.Dhcp.Address.Address); } } catch (Exception ex) { sb.AppendLine("Failed to get IP config info."); sb.AppendLine(ex.GetType().ToString() + " - " + ex.Message); } this.MarshalUpdateCommandOutput(sb.ToString()); }); Task continuationTask = getTask.ContinueWith( (t) => { this.MarshalEnableDeviceControls(true); this.MarshalEnableConnectionControls(true); }); getTask.Start(); }
/// <summary> /// Click handler for the getIpConfig button. /// </summary> /// <param name="sender">The caller of this method.</param> /// <param name="e">The arguments associated with this event.</param> private async void GetIPConfig_Click(object sender, RoutedEventArgs e) { this.ClearOutput(); this.EnableConnectionControls(false); this.EnableDeviceControls(false); StringBuilder sb = new StringBuilder(); sb.Append(commandOutput.Text); sb.AppendLine("Getting IP configuration..."); commandOutput.Text = sb.ToString(); try { IpConfiguration ipconfig = await portal.GetIpConfigAsync(); foreach (NetworkAdapterInfo adapterInfo in ipconfig.Adapters) { sb.Append(" "); sb.AppendLine(adapterInfo.Description); sb.Append(" MAC address :"); sb.AppendLine(adapterInfo.MacAddress); foreach (IpAddressInfo address in adapterInfo.IpAddresses) { sb.Append(" IP address :"); sb.AppendLine(address.Address); } sb.Append(" DHCP address :"); sb.AppendLine(adapterInfo.Dhcp.Address.Address); } } catch (Exception ex) { sb.AppendLine("Failed to get IP config info."); sb.AppendLine(ex.GetType().ToString() + " - " + ex.Message); } commandOutput.Text = sb.ToString(); EnableDeviceControls(true); EnableConnectionControls(true); }