/// <summary> /// </summary> /// <param name="ar"></param> private void OnGetHostEntry( [CanBeNull] IAsyncResult ar) { try { if (ar != null) { var hostNameItem = ar.AsyncState as ListViewItem.ListViewSubItem; ThreadSwitch threadSwitchDelegate = delegate { if (hostNameItem != null) { var endGetHostEntry = Dns.EndGetHostEntry(ar); if ( endGetHostEntry != null) { hostNameItem.Text = endGetHostEntry .HostName; } } }; this.Invoke(threadSwitchDelegate); } } // ReSharper disable EmptyGeneralCatchClause catch (Exception) // ReSharper restore EmptyGeneralCatchClause { } }
public async Task ThreadSwitching() { var stock = new Stock(); Assert.IsNull(SynchronizationContext.Current); await ThreadSwitch.To(stock); Assert.AreEqual(stock, SynchronizationContext.Current); }
private void OnGetHostEntry(IAsyncResult ar) { try { ListViewItem.ListViewSubItem hostNameItem = ar.AsyncState as ListViewItem.ListViewSubItem; ThreadSwitch delg = delegate { hostNameItem.Text = Dns.EndGetHostEntry(ar).HostName; }; this.Invoke(delg); } catch (SocketException ex) { Trace.WriteLine(ex.ToString()); } }