private void exWebBrowser1_NewWindow3(object sender, ExControls.ComponentModel.ExWebBrowserNewWindow3EventArgs e) { if (e == null) { throw new ArgumentNullException("e"); } WebPageNewPageEventArgs args = new WebPageNewPageEventArgs(e.ActiveXInstance); NewPage?.Invoke(this, args); e.ActiveXInstance = args.ActiveXInstance; e.Cancel = args.Cancel; }
/// <summary> /// Difference between this method and the one above is the one above /// gets all data at once which uses more memory at once while this one /// is a smaller footprint as the SQL is paged. /// </summary> /// <param name="delay"></param> /// <returns></returns> public static async IAsyncEnumerable <string> GetAllNamesPaged(bool delay) { var pageIndex = 0; const int pageSize = 10; var hasMore = false; do { await using var cn = new SqlConnection(Helper.ConnectionString()); await using var cmd = new SqlCommand { Connection = cn, CommandText = _selectStatement }; cmd.CommandText = "SELECT FirstName + ' ' + LastName As FullName FROM dbo.Contacts ORDER BY LastName " + $"OFFSET {pageIndex * pageSize} ROWS FETCH NEXT {pageSize} ROWS ONLY;"; await cn.OpenAsync(new CancellationTokenSource(TimeSpan.FromSeconds(GlobalStuff.TimeOutSeconds)).Token); await using var reader = await cmd.ExecuteReaderAsync(); while (reader.Read()) { if (delay) { await Task.Delay(GlobalStuff.TimeSpan); } yield return(reader.GetString(0)); } pageIndex++; NewPage?.Invoke(pageIndex); hasMore = reader.HasRows; } while (hasMore); }
/// <summary> /// Raises the NewPage event /// </summary> /// <param name="e">the arguments for the NewPage event</param> protected virtual void OnNewPage(NewPageEventArgs e) { NewPage?.Invoke(this, e); }