public async Task Announce_CancelAfter () { var cts = new CancellationTokenSource(); var announcer = new UdpBroadcast(); var task = announcer.BeginAnnouncingAsync (12345, cts.Token); cts.Cancel(); await Asserts.IsCancelled(task); }
public async Task Listen_CancelBefore () { var cts = new CancellationTokenSource(); var announcer = new UdpBroadcast(); cts.Cancel(); var task = announcer.BeginListeningAsync(cts.Token); await Asserts.IsCancelled(task); }
async void SearchForServers () { var announceListener = new UdpBroadcast (); announceListener.ServerFound += (o, e) => { if (!Servers.Contains (e)) { Servers.Add (e); serverTableView.ReloadData (); } }; await announceListener.BeginListeningAsync(searchCancellation.Token).WaitOrCanceled(); }
static async Task Initialize (CancellationToken token) { var catalog = await LoadCatalog (token); handler = new RequestHandler { Catalog = catalog }; announcer = new UdpBroadcast (); try { await Task.WhenAll (new [] { handler.BeginListeningAsync (token), announcer.BeginAnnouncingAsync (handler.ListenPort, token) }); } catch (OperationCanceledException) { } }