public static List <AATest> GetDataByCon2(string strMdx) { List <AATest> list = new List <AATest>(); try { if (_connection != null) { if (_connection.State == ConnectionState.Closed) { _connection.Open(); } Stopwatch sw = new Stopwatch(); //开始计时 sw.Start(); AdomdCommand cmd = _connection.CreateCommand(); cmd.CommandText = strMdx; AdomdDataReader reader = cmd.ExecuteReader(); //Execute query while (reader.Read()) // read { AATest dt = new AATest(); // custom class dt.A = reader[0] == null ? "" : reader[0].ToString(); dt.B = reader[1] == null ? "" : reader[1].ToString(); dt.C = reader[2] == null ? "" : reader[2].ToString(); dt.D = reader[3] == null?"":reader[3].ToString(); dt.E = reader[4] == null ? "":reader[4].ToString(); dt.F = reader[5] == null ? "" : reader[5].ToString(); dt.G = reader[6] == null ? "" : reader[6].ToString(); //dt.H = reader[7].ToString(); //dt.I = reader[8].ToString(); //dt.J = reader[9].ToString(); //dt.K = reader[10].ToString(); list.Add(dt); } sw.Stop(); //获取运行时间[毫秒] long times = sw.ElapsedMilliseconds; Console.WriteLine($"耗时2——{times}"); _connection.Close(); } return(list); } catch (Exception ex) { throw ex; } }
static void Main(string[] args) { ThreadLogger logger = new ThreadLogger(new ConsoleLogWriter()); logger.LogMethodNumber = 4; var test = new AATest(logger); test.UseInnerLogMethodNames = true; // WTF with this execution? See: https://habrahabr.ru/post/232169/ and https://msdn.microsoft.com/en-us/magazine/gg598924.aspx test.Execute(); Console.WriteLine("Press any key to continue . . ."); Console.ReadKey(); }
private static void StartWithContext() { Console.WriteLine($"2Has SynchronizationContext? {SynchronizationContext.Current != null}"); using (new DummyForm()) { //SynchronizationContext.SetSynchronizationContext(new WindowsFormsSynchronizationContext()); Console.WriteLine($"3Has SynchronizationContext? {SynchronizationContext.Current != null}"); ThreadLogger logger = new ThreadLogger(new ConsoleLogWriter()); logger.LogMethodNumber = 4; var test = new AATest(logger); test.UseInnerLogMethodNames = true; // WTF with this execution? See: https://habrahabr.ru/post/232169/ and https://msdn.microsoft.com/en-us/magazine/gg598924.aspx test.Execute(); //new Thread(StartWithContext).Start(SynchronizationContext.Current); Console.WriteLine("Worker thread exited."); } Console.WriteLine($"4Has SynchronizationContext? {SynchronizationContext.Current != null}"); }