コード例 #1
0
        static void Main(string[] args)
        {
            string
                Message;

            LogFile
                Log = null;

            try
            {
                Log = new LogFile();
                Log.Open("main_thread");

                Message = DateTime.Now.ToString("HH:mm:ss.ffff") + '\t' + "Main thread started...";
                Log.File.WriteLine(Message);
                Console.WriteLine(Message);

                if (args.Length < 2)
                {
                    Message = DateTime.Now.ToString("HH:mm:ss.ffff") + '\t' + "Main thread  finished (Too few parameters in command line)";
                    Log.File.WriteLine(Message);
                    Console.WriteLine(Message);
                    return;
                }

                AppData
                    AppData = new AppData();

                AppData.ParseCmdLine(args);

                if (AppData.ConnectionCount == int.MinValue)
                {
                    Message = DateTime.Now.ToString("HH:mm:ss.ffff") + '\t' + "Main thread  finished (Invalid connection's count)";
                    Log.File.WriteLine(Message);
                    Console.WriteLine(Message);
                    return;
                }
                if (AppData.Sec == int.MinValue)
                {
                    Message = DateTime.Now.ToString("HH:mm:ss.ffff") + '\t' + "Main thread  finished (Invalid second's value)";
                    Log.File.WriteLine(Message);
                    Console.WriteLine(Message);
                    return;
                }

                AppData.ReadIniFile();

                ArrayList
                    Connections = new ArrayList();

                int
                    i;

                if (AppData.TestMultiThread)
                {
                    for (i = 0; i < AppData.ConnectionCount; ++i)
                    {
                        Connections.Add(new SybaseConnection(AppData.Sec, "#" + i, AppData.SQLs));
                    }

                    bool
                        IsAlive;

                    do
                    {
                        Console.Write(".");
                        Thread.Sleep(1000);

                        IsAlive = false;
                        for (i = 0; i < Connections.Count; ++i)
                        {
                            IsAlive |= ((SybaseConnection)Connections[i]).Thread.IsAlive;
                        }
                    }while(IsAlive);

                    Message = DateTime.Now.ToString("HH:mm:ss.ffff") + '\t' + "All thread(s) finished";
                    Log.File.WriteLine(Message);
                    Console.WriteLine(Message);
                }

                bill.DbProvider
                    DbProvider;

                object
                    tmpObject;

                Connections.Clear();

                for (i = 0; i < AppData.ConnectionCount; ++i)
                {
                    DbProvider = new bill.DbProvider();

                    Message = DateTime.Now.ToString("HH:mm:ss.ffff") + '\t' + "Main thread: connection# " + i + " opened";
                    Log.File.Write(Message);
                    Console.Write(Message);

                    Connections.Add(DbProvider);

                    if ((tmpObject = DbProvider.ExecScalar("select count(*) from master..sysprocesses where (suid=1)")) != null)
                    {
                        Message = " (processes count: " + Convert.ToInt32(tmpObject) + ")";
                        if ((tmpObject = DbProvider.ExecScalar("select @@spid")) != null)
                        {
                            Message += " (@@SPID=" + Convert.ToInt32(tmpObject) + ")";
                        }
                        Log.File.Write(Message);
                        Console.Write(Message);
                    }
                    Message = "...";
                    Log.File.WriteLine(Message);
                    Console.WriteLine(Message);
                }

                for (i = 0; i < AppData.Sec; ++i)
                {
                    Console.Write(".");
                    Thread.Sleep(1000);
                }

                if (AppData.SQLs.Count > 0)
                {
                    DataTable
                        tmpDataTable = new DataTable();

                    Random
                        rnd = new Random(unchecked ((int)DateTime.Now.Ticks));

                    string
                        SQLText;

                    int
                        idx;

                    for (i = 0; i < Connections.Count; ++i)
                    {
                        if ((DbProvider = Connections[i] as bill.DbProvider) == null)
                        {
                            continue;
                        }

                        for (int s = 0; s < AppData.SQLs.Count; ++s)
                        {
                            tmpDataTable.Reset();

                            SQLText = (string)AppData.SQLs[idx = rnd.Next(AppData.SQLs.Count)];

                            Message = DateTime.Now.ToString("HH:mm:ss.ffff") + '\t' + "Main thread connection# " + i + " SQLText[" + idx + "]:" + Environment.NewLine + Environment.NewLine + "\"" + SQLText + "\"" + Environment.NewLine;
                            Log.File.WriteLine(Message);
                            Console.WriteLine(Message);

                            DbProvider.FillDataTable(SQLText, ref tmpDataTable);

                            Message = DateTime.Now.ToString("HH:mm:ss.ffff") + '\t' + "Main thread connection# " + i + " SQLText[" + idx + "] done";
                            Log.File.WriteLine(Message);
                            Console.WriteLine(Message);

                            Thread.Sleep(1000);
                        }
                    }
                }

                Log.File.WriteLine();
                Console.WriteLine();
            }
            catch (OleDbException eException)
            {
                Message = eException.GetType().FullName + Environment.NewLine + "ErrorCode=" + eException.ErrorCode.ToString() + Environment.NewLine + "Message: " + eException.Message + Environment.NewLine + "StackTrace:" + Environment.NewLine + eException.StackTrace;
                Log.File.WriteLine(Message);
                Console.WriteLine(Message);
            }
            catch (Exception eException)
            {
                Message = eException.GetType().FullName + Environment.NewLine + "Message: " + eException.Message + Environment.NewLine + "StackTrace:" + Environment.NewLine + eException.StackTrace;
                Log.File.WriteLine(Message);
                Console.WriteLine(Message);
            }

            Message = DateTime.Now.ToString("HH:mm:ss.ffff") + '\t' + "Main thread finished";
            Log.File.WriteLine(Message);
            Console.WriteLine(Message);

            Console.ReadLine();
        }
コード例 #2
0
 public AppData(AppData aObj) : this(aObj.ConnectionCount, aObj.Sec, aObj.TestMultiThread, aObj.IniFileName)
 {
 }