private void searchButton_Click(object sender, EventArgs e) { if (_currentPage == 0) { ShowResultsPage(); } if (_searchCts != null) { Console.WriteLine("cancel"); _searchCts.Cancel(); } _searchCts = new CancellationTokenSource(); _queryMethod.BeginInvoke(searchTb.Text, new AsyncCallback(new AsyncPoppulateSearch(_queryMethod, this, _searchCts).PopulateSearch), null); }
/// <summary> /// Query a whois server specifying the specified ServerCollection object and domain to query asynchronously. /// </summary> /// <param name="servers">Collection contening a list of whois server.</param> /// <param name="domainToQuery">Domain to query.</param> /// <param name="callBack">Callback function</param> /// <returns>IAsyncResult object that represents the result of the QueryAsync operation.</returns> /// <example> /// <code> /// [C#] /// /// ServerCollection servers = new ServerCollection(); /// /// Server server1 = new Server(); /// server1.Host = "whois.networksolutions.com"; /// server1.Port = 43; /// server1.Domain = ".com"; /// servers.Add(server1); /// /// Server server2 = new Server(); /// server2.Host = "whois.nic.co.uk"; /// server2.Port = 43; /// server2.Domain = ".co.uk"; /// servers.Add(server2); /// /// WhoIs whoIs = new WhoIs(); /// IAsyncResult state = whoIs.QueryAsync(servers,"activeup.com",new AsyncCallback(MyCallbackWhoIs)); /// /// public void MyCallbackWhoIs(IAsyncResult state) /// { /// try /// { /// string result = whoIs.QueryAsyncResult(state); /// Console.WriteLine(result); /// } /// /// catch(WhoisException we) /// { /// Console.WriteLine("WhoisException : " + we.Message); /// } /// /// catch(Exception ex) /// { /// Console.WriteLine("An unhandled exception was thrown : " + ex.Message); /// } /// } /// /// [VB.NET] /// /// Private whoIs As whoIs = New whoIs() /// /// Dim servers As New ServerCollection() /// /// Dim server1 As New Server() /// server1.Host = "whois.networksolutions.com" /// server1.Port = 43 /// server1.Domain = ".com" /// servers.Add(server1) /// /// Dim server2 As New Server() /// server2.Host = "whois.nic.co.uk" /// server2.Port = 43 /// server2.Domain = ".co.uk" /// servers.Add(server2) /// Dim state As IAsyncResult = whoIs.QueryAsync(servers, New AsyncCallback(AddressOf MyCallbackWhoIs)) /// /// Public Sub MyCallbackWhoIs(ByVal state As IAsyncResult) /// /// Try /// /// Dim result As String = whoIs.QueryAsyncResult(state) /// Console.WriteLine(result) /// /// Catch we As WhoisException /// Console.WriteLine("WhoisException : " + we.Message) /// /// Catch ex As Exception /// Console.WriteLine("An unhandled exception was thrown : " + ex.Message) /// /// End Try /// /// End Sub /// </code> /// </example> public IAsyncResult QueryAsync(ServerCollection servers, string domainToQuery,AsyncCallback callBack) { _queryDelegate = new QueryDelegate(_Query); return _queryDelegate.BeginInvoke(servers,domainToQuery,false,callBack,null); }
/// <summary> /// Query a whois server specifying the specified host, port and domain to query asynchronously. /// </summary> /// <param name="host">Host of the whois server.</param> /// <param name="port">Port of the whois server.</param> /// <param name="domainToQuery">Domain to query.</param> /// <param name="callBack">Callback function.</param> /// <returns>IAsyncResult object that represents the result of the QueryAsync operation.</returns> /// <example> /// <code> /// [C#] /// /// WhoIs whoIs = new WhoIs(); /// IAsyncResult state = whoIs.QueryAsync("whois.networksolutions.com",43,"activeup.com",new AsyncCallback(MyCallbackWhoIs)); /// /// public void MyCallbackWhoIs(IAsyncResult state) /// { /// try /// { /// string result = whoIs.QueryAsyncResult(state); /// Console.WriteLine(result); /// } /// /// catch(WhoisException we) /// { /// Console.WriteLine("WhoisException : " + we.Message); /// } /// /// catch(Exception ex) /// { /// Console.WriteLine("An unhandled exception was thrown : " + ex.Message); /// } /// } /// /// [VB.NET] /// /// Private whoIs As whoIs = New whoIs() /// Dim state As IAsyncResult = whoIs.QueryAsync("whois.networksolutions.com",43,"activeup.com", New AsyncCallback(AddressOf MyCallbackWhoIs)) /// /// Public Sub MyCallbackWhoIs(ByVal state As IAsyncResult) /// /// Try /// /// Dim result As String = whoIs.QueryAsyncResult(state) /// Console.WriteLine(result) /// /// Catch we As WhoisException /// Console.WriteLine("WhoisException : " + we.Message) /// /// Catch ex As Exception /// Console.WriteLine("An unhandled exception was thrown : " + ex.Message) /// /// End Try /// /// End Sub /// </code> /// </example> public IAsyncResult QueryAsync(string host, int port, string domainToQuery,AsyncCallback callBack) { ServerCollection servers = new ServerCollection(); servers.Add(new Server(host,port)); _queryDelegate = new QueryDelegate(_Query); return _queryDelegate.BeginInvoke(servers,domainToQuery,false,callBack,null); }
/// <summary> /// Query a whois server specifying the specified domain to query asynchronously. In this case, it uses the default whois servers. /// </summary> /// <param name="domainToQuery">Domain to query.</param> /// <param name="callBack">Callback function.</param> /// <returns>IAsyncResult object that represents the result of the QueryAsync operation.</returns> /// <example> /// <code> /// [C#] /// /// WhoIs whoIs = new WhoIs(); /// IAsyncResult state = whoIs.QueryAsync("activeup.com",new AsyncCallback(MyCallbackWhoIs)); /// /// public void MyCallbackWhoIs(IAsyncResult state) /// { /// try /// { /// string result = whoIs.QueryAsyncResult(state); /// Console.WriteLine(result); /// } /// /// catch(WhoisException we) /// { /// Console.WriteLine("WhoisException : " + we.Message); /// } /// /// catch(Exception ex) /// { /// Console.WriteLine("An unhandled exception was thrown : " + ex.Message); /// } /// } /// /// [VB.NET] /// /// Private whoIs As whoIs = New whoIs() /// Dim state As IAsyncResult = whoIs.QueryAsync("activeup.com", New AsyncCallback(AddressOf MyCallbackWhoIs)) /// /// Public Sub MyCallbackWhoIs(ByVal state As IAsyncResult) /// /// Try /// /// Dim result As String = whoIs.QueryAsyncResult(state) /// Console.WriteLine(result) /// /// Catch we As WhoisException /// Console.WriteLine("WhoisException : " + we.Message) /// /// Catch ex As Exception /// Console.WriteLine("An unhandled exception was thrown : " + ex.Message) /// /// End Try /// /// End Sub /// </code> /// </example> public IAsyncResult QueryAsync(string domainToQuery,AsyncCallback callBack) { _queryDelegate = new QueryDelegate(_Query); return _queryDelegate.BeginInvoke(null,domainToQuery,false,callBack,null); }