Beispiel #1
0
        public static void Cozy()
        {
            Console.WriteLine("\n-----------------------------------------------");
            Console.WriteLine(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);
            Console.WriteLine("-----------------------------------------------");

            var t1 = new Thread(ThreadMain);
            t1.Name = "First";
            var t2 = new Thread(ThreadMain);
            t2.Name = "Second";
            t1.Priority = ThreadPriority.Highest;
            t2.Priority = ThreadPriority.Lowest;
            t1.Start();
            t2.Start();

            FirstThread();

            t1 = new Thread(ThreadMain);
            t1.Name = "MyNewThread1";
            t1.IsBackground = true;
            t1.Start();
            Console.WriteLine("Main thread ending now...");

            var d = new Data { Message = "Info" };
            t2 = new Thread(ThreadMainWithParameters);
            t2.Start(d);

            var obj = new MyThread("info");
            var t3 = new Thread(obj.ThreadMain);
            t3.Start();
        }
 static void Main()
 {
     TickTock tt = new TickTock();
     MyThread mtl = new MyThread("Tick", tt);
     MyThread mt2 = new MyThread("Tock", tt);
     mtl.Thrd.Join();
     mt2.Thrd.Join();
     Console.WriteLine("Часы остановлены");
 }
Beispiel #3
0
public static void Main()
{
Console.WriteLine("Entering main thread");

MyThread m1 = new MyThread("Child 1");
MyThread m2 = new MyThread("Child 2");
MyThread m3 = new MyThread("Child 3");
Thread.Sleep(1000);
Console.WriteLine("Exiting MainThread");
}
        static void Main(string[] args)
        {
            var tt  = new TickTock();
            var mt1 = new MyThread("Tick", tt);
            var mt2 = new MyThread("Tock", tt);

            mt1.Thrd.Join();
            mt2.Thrd.Join();

            Console.WriteLine("Часы остановлены.");
        }
Beispiel #5
0
    // Main Method
    public static void Main()
    {
        // Creating object of MYTHREAD class
        MyThread obj = new MyThread();

        // Creating a thread which
        // calls a parameterized instance method
        Thread thr = new Thread(obj.Job);

        thr.Start();
    }
            public static void Main()
            {
                TickTock tt  = new TickTock();
                MyThread mt1 = new MyThread("Tick", tt);
                MyThread mt2 = new MyThread("Tock", tt);

                mt1.thrd.Join();
                mt2.thrd.Join();
                Console.WriteLine("Clock  Stopped");
                Console.Read();
            }
Beispiel #7
0
    static void Main()
    {
        // Construct three threads.
        MyThread mt1 = new MyThread("Thread #1");
        MyThread mt2 = new MyThread("Thread #2");
        MyThread mt3 = new MyThread("Thread #3");

        mt1.Thrd.Join();
        mt2.Thrd.Join();
        mt3.Thrd.Join();
    }
Beispiel #8
0
public static void Main()
{
Console.WriteLine("Entering Main thread");
MyThread mt1 = new MyThread("Child 1", 5);
MyThread mt2 = new MyThread("Child 2", 3);
do
{
Thread.Sleep(100);
}while(mt1.th.IsAlive | mt2.th.IsAlive);
Console.WriteLine("exiting Main thread");
}
Beispiel #9
0
    void Start()
    {
        //第一种开启线程的方法
        var t1 = new Thread(ThreadMain);

        t1.Start();
        //t1.Abort();//终止这个线程的执行
        t1.Join();//当前线程睡眠,等待t1线程执行完,然后继续运行下面的代码

        //Thread类-Lambda表达式
        var t2 = new Thread(() => Debug.Log("Running in a thread, id : " + Thread.CurrentThread.ManagedThreadId));

        t2.Start();

        //给线程传递数据-通过委托
        var d = new Data {
            Message = "给线程传递数据-通过委托"
        };
        var t3 = new Thread(ThreadMainWithParameters);

        t3.Start(d);

        //给线程传递数据-自定义类
        var obj = new MyThread("给线程传递数据-自定义类");
        var t4  = new Thread(obj.ThreadMain);

        t4.IsBackground = true;//设置为后台线程
        t4.Start();

        //线程池
        ThreadPool.QueueUserWorkItem(ThreadMethod);
        ThreadPool.QueueUserWorkItem(ThreadMethod);
        ThreadPool.QueueUserWorkItem(ThreadMethod);

        //任务
        //第一种开启方式
        //Task t5 = new Task(ThreadMethod);
        //t5.Start();
        //第二种开始方式
        //TaskFactory tf = new TaskFactory();
        //Task t6 = tf.StartNew(ThreadMethod);
        //任务有父子关系
        //如果父任务执行完了但是子任务没有执行完,它的状态会设置为WaitingForChildrenToComplete
        //只有子任务也执行完了,父任务的状态就变成RunToCompletion
        //Task task1 = new Task(DoFirst);
        //Task task2 = task1.ContinueWith(DoSecond);//父任务是task1
        //Task task3 = task1.ContinueWith(DoSecond);//父任务是task1
        //Task task4 = task2.ContinueWith(DoSecond);//父任务是task2



        Debug.Log("This is the main thread.");
    }
Beispiel #10
0
    public static void MainRun()
    {
        Console.WriteLine("Before start thread");

        MyThread thr = new MyThread();

        Thread tid1 = new Thread(new ThreadStart(thr.Thread1));
        Thread tid2 = new Thread(new ThreadStart(thr.Thread2));

        tid1.Start();
        tid2.Start();
    }
Beispiel #11
0
        private void OpenThread()
        {
            ArrayList  b = GetAll();
            MainWindow s = (MainWindow)this.owner;

            s.f.myINI.Clear();//开始时清空所有Fiddler链接
            foreach (MyINI a in b)
            {
                MyThread c = new MyThread(SetMyListBox);
                this.Dispatcher.Invoke(c, new object[] { a });//执行唤醒操作
            }
        }
Beispiel #12
0
 public void Startする前はThreadBaseKindはBeforeとなる()
 {
     //setUp
     var sut = new MyThread();
     var expected = ThreadBaseKind.Before;
     //exercise
     var actual = sut.ThreadBaseKind;
     //verify
     Assert.That(actual, Is.EqualTo(expected));
     //tearDown
     sut.Dispose();
 }
Beispiel #13
0
 public void new及びstart_stop_disposeしてisRunnigの状態を確認する_負荷テスト()
 {
     //exercise verify
     for (var i = 0; i < 3; i++){
         var sut = new MyThread();
         sut.Start();
         Assert.That(sut.ThreadBaseKind, Is.EqualTo(ThreadBaseKind.Running));
         sut.Stop();
         Assert.That(sut.ThreadBaseKind, Is.EqualTo(ThreadBaseKind.After));
         sut.Dispose();
     }
 }
Beispiel #14
0
 public SocketConnectServer()
 {
     mClientList      = new Dictionary <uint, NetClient>();
     mMaxReceiveCount = 1024 * 1024 * 8;
     mClientSendLock  = new ThreadLock();
     mClientRecvLock  = new ThreadLock();
     mAcceptThread    = new MyThread("AcceptThread");
     mReceiveThread   = new MyThread("SocketReceive");
     mSendThread      = new MyThread("SocketSend");
     mRecvBuff        = new byte[mMaxReceiveCount];
     mHeartBeatTimer  = new MyTimer();
 }
Beispiel #15
0
        static void Main(string[] args)
        {
            MyThread t1 = new MyThread();

            t1.StartThread();
            for (int i = 0; i < 100; i++)
            {
                Console.SetCursorPosition(i, 0);
                Console.Write("-");
                Thread.Sleep(1000);
            }
        }
 static void Main()
 {
     Console.WriteLine("Основной поток начат.");
     // Сначала сконструировать объект типа MyThread.
     MyThread mt = new MyThread("Потомок #1");
     do
     {
         Console.Write(".");
         Thread.Sleep (100);
     } while (mt.Count != 10);
     Console.WriteLine("Основной поток завершен.");
 }
Beispiel #17
0
        //ORIGINAL LINE: @Test public void testSync_DiffAddressOnePort() throws ThreadInterruptedException
        //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
        public virtual void testSync_DiffAddressOnePort()
        {
            for (int i = 0; i < invokeTimes; ++i)
            {
                Url      url    = new Url(IPAddress.Parse(ip_prefix + i), port); //127.0.0.1:12200, 127.0.0.2:12200, 127.0.0.3:12200...
                MyThread thread = new MyThread(this, url, 1, false);
                new java.lang.Thread(thread).start();
            }

            System.Threading.Thread.Sleep(5000);
            Assert.False(whetherConnectTimeoutConsumedTooLong.get());
        }
Beispiel #18
0
    public static void Main()
    {
        MyThread mt1 = new MyThread("Мой поток");

        Thread.Sleep(1000); // Разрешаем стартовать
                            // дочернему потоку.
        Console.WriteLine("Прерывание выполнения потока.");
        mt1.thrd.Abort(100);
        mt1.thrd.Join(); // Ожидаем завершения
                         // выполнения потока.
        Console.WriteLine("Основной поток завершен.");
    }
Beispiel #19
0
        static void Main(string[] args)
        {
            int numberOfThreads = 10;

            for (int i = 0; i < numberOfThreads; i++)
            {
                MyThread thr = new MyThread();
                Thread   tid = new Thread(new ThreadStart(thr.NewThread));
                tid.Name = $"t{i}";
                tid.Start();
            }
        }
Beispiel #20
0
    public static void Main()
    {
        MyThread mt = new MyThread();
        Thread   t1 = new Thread(new ThreadStart(mt.Thread1));
        Thread   t2 = new Thread(new ThreadStart(mt.Thread1));
        Thread   t3 = new Thread(new ThreadStart(mt.Thread1));

        t1.Start();
        t1.Join();
        t2.Start();
        t3.Start();
    }
Beispiel #21
0
            public override void OnCreate(Bundle p0)
            {
                base.OnCreate(p0);

                // Tell the framework to try to keep this fragment around
                // during a configuration change.
                RetainInstance = true;

                // Start up the worker thread.
                myThread = new MyThread(this);
                myThread.Start();
            }
            public override void OnCreate(Bundle p0)
            {
                base.OnCreate (p0);

                // Tell the framework to try to keep this fragment around
                // during a configuration change.
                RetainInstance = true;

                // Start up the worker thread.
                myThread = new MyThread (this);
                myThread.Start ();
            }
Beispiel #23
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="index">Used to check if must start in this files index or in index + 1</param>
        public void Skip(int index)
        {
            try
            {
                //if (State == CopyHandleState.Runing && FileCopier.Writer != null)
                //{

                myThread.Pause();

                //If there is any file in copy process then stop copy,
                //free resources and delete the file with Cancel method.
                if (FileCopier.CurrentFile != null)
                {
                    FileCopier.CurrentFile.CopyState = CopyState.Skiped;
                    FileCopier.Skip();
                }

                //Terminate the copy process
                myThread.Cancel();

                myThread = new MyThread(new Action(() =>
                {
                    if (Operation != null)
                    {
                        Operation.Invoke();

                        RaiseFinished(Errors);

                        Errors.Clear();
                    }
                }));

                if (DiscoverdList.Index == index)
                {
                    DiscoverdList.Index++;
                    CopiedsFiles++;
                }

                myThread.Start();
                //}
            }
            catch (Exception ex)
            {
                MessageBox.Show(Error.GetErrorLog(ex.Message, "NeathCopyEngine", "NeathCopyHandle", "Skip"));
                using (var w = new StreamWriter(new FileStream(logsPath, FileMode.Append, FileAccess.Write)))
                {
                    w.WriteLine("-------------------------------");
                    w.WriteLine(System.DateTime.Now);
                    w.WriteLine(Error.GetErrorLogInLine(ex.Message, "NeathCopyEngine", "NeathCopyHandle", "Skip"));
                }
            }
        }
Beispiel #24
0
    public static void StartWithThread(System.Threading.ThreadStart s, int timeout_second, string message)
    {
        var performed = false;

        while (!performed)
        {
            var tr = new System.Threading.Thread(s);

            try
            {
                tr.Start();

                var co = 1;

                while (co < timeout_second + 1)
                {
                    System.Threading.Thread.Sleep(1000);

                    if (co > 1)
                    {
                        Console.SetCursorPosition(0, Console.CursorTop - 1);
                    }
                    Console.WriteLine($"{message} {co} second");


                    if (tr.ThreadState == ThreadState.Stopped)
                    {
                        performed = true;
                        break;
                    }
                    co++;
                }

                if (!performed)
                {
                    tr.Interrupt();
                    MyConsole.WriteLine_Error($"{message} not ended on {timeout_second} seconds - restarting on 10 seconds -------\n");
                    MyThread.GenerateConsoleWaiting(10);
                }

                if (performed)
                {
                    MyConsole.WriteLine_Succ(message + $" Ended in {co} seconds !!!");
                }
            }
            catch (Exception ex)
            {
                MyConsole.WriteLine_Exception("error in executing " + message, ex);
                throw new Exception(ex.Message);
            }
        }
    }
Beispiel #25
0
    static void Main()
    {
        Console.WriteLine("Основной поток начат.");
        // Сначала сконструировать объект типа MyThread.
        MyThread mt = new MyThread("Потомок #1");

        do
        {
            Console.Write(".");
            Thread.Sleep(100);
        } while (mt.Count != 10);
        Console.WriteLine("Основной поток завершен.");
    }
Beispiel #26
0
 public void new及びstart_stop_disposeしてisRunnigの状態を確認する_負荷テスト()
 {
     //exercise verify
     for (var i = 0; i < 3; i++)
     {
         var sut = new MyThread();
         sut.Start();
         Assert.That(sut.ThreadBaseKind, Is.EqualTo(ThreadBaseKind.Running));
         sut.Stop();
         Assert.That(sut.ThreadBaseKind, Is.EqualTo(ThreadBaseKind.After));
         sut.Dispose();
     }
 }
        public static void MyThreadImprovedTest(MyThread myThread)
        {
            Console.WriteLine("\t<<< Class \"MyThreadImproved\" Test >>>");

            do
            {
                Console.Write(".");
                Thread.Sleep(100);
            } while (myThread.Count != 10);


            Console.WriteLine("\t\\\\  Class \"MyThreadImproved\" Test //\n");
        }
Beispiel #28
0
        public void Startする前はThreadBaseKindはBeforeとなる()
        {
            //setUp
            var sut      = new MyThread();
            var expected = ThreadBaseKind.Before;
            //exercise
            var actual = sut.ThreadBaseKind;

            //verify
            Assert.That(actual, Is.EqualTo(expected));
            //tearDown
            sut.Dispose();
        }
Beispiel #29
0
    public static void Main()
    {
        Console.WriteLine("Multithreading in C#");
        MyThread thr1 = new MyThread();
        MyThread thr2 = new MyThread();
        Thread   act1 = new Thread(new ThreadStart(thr1.Activity1));

        act1.Start();

        Thread act2 = new Thread(new ThreadStart(thr2.Activity2));

        act2.Start();
    }
Beispiel #30
0
 public void StartするとThreadBaseKindはRunningとなる()
 {
     //setUp
     var sut = new MyThread();
     var expected = ThreadBaseKind.Running;
     //exercise
     sut.Start();
     var actual = sut.ThreadBaseKind;
     //verify
     Assert.That(actual, Is.EqualTo(expected));
     //tearDown
     sut.Dispose();
 }
Beispiel #31
0
    static void Main()
    {
        // Обратите внимание на то, что число повторений
        // передается этим двум объектам типа MyThread.
        MyThread mt  = new MyThread("Потомок #1", 5);
        MyThread mt2 = new MyThread("Потомок #2", 3);

        do
        {
            Thread.Sleep(100);
        } while (mt.Thrd.IsAlive || mt2.Thrd.IsAlive);
        Console.WriteLine("Основной поток завершен.");
    }
    public static void Main()
    {
        Console.WriteLine("Основной поток стартовал.");
        // Сначала создаем объект класса MyThread.
        MyThread mt = new MyThread("Потомок #1");

        do
        {
            Console.Write(".");
            Thread.Sleep(10);
        } while (mt.count != 10);
        Console.WriteLine("Основной поток завершен.");
    }
    static void Main()
    {
        MyThread mt1 = new MyThread("My Thread");

        Thread.Sleep(1000); // let child thread start executing

        Console.WriteLine("Stopping thread.");

        mt1.Thrd.Abort();
        mt1.Thrd.Join(); // wait for thread to terminate

        Console.WriteLine("Main thread terminating.");
    }
Beispiel #34
0
    public void ThreadTest()
    {
        // start a thread using a static function
        ThreadStart simpleThread = new ThreadStart(SimpleThreadFunc);

        for (int i = 1; i < 6; i++)
        {
            // pass parameters to thread through static variables
            // useful to start 1 or more threads with the same parameters
            Thread thread = new Thread(simpleThread);
            // quickly fire off the threads, they will use the lock keyword to execute one at a time
            thread.Start();  // start a new thread
        }
        Thread.Sleep(1000);  // let the locking threads complete
        Console.WriteLine();

        // pass parameters to thread using the parameterized method
        for (int i = 1; i < 6; i++)
        {
            Thread pts = new Thread(new ParameterizedThreadStart(ParameterizedThreadFunc));
            pts.Start(new Parameters(i + 10, i * 10.3d, string.Format("parameter string{0}", i)));
            Thread.Sleep(500);  // let the thread run now
        }
        Console.WriteLine();

        // start a thread with parameters using a class provides an easy way to start threads with
        // a different set of parameters
        for (int i = 1; i < 6; i++)
        {
            using (MyThread mt = new MyThread(i, i * 2.5d, string.Format("string{0}", i)))
            {
                ThreadStart classThread = new ThreadStart(mt.MyThreadFunc);
                Thread      thread      = new Thread(classThread);
                thread.Start();      // start a new thread
                mt.signal.WaitOne(); // let the thread signal when done
                Console.WriteLine("thread return code was {0}", mt.retCode);
                mt.signal.Dispose(); // free up the event handle
            }
        }
        Console.WriteLine();

        // the .net framework provides a pool of threads ready to run skipping the overhead
        // of thread creation and can be used for small amounts of work to be done
        ThreadPool.QueueUserWorkItem(new WaitCallback(ThreadPoolFunc), "hello there");
        Thread.Sleep(1000);
        ThreadPool.QueueUserWorkItem(new WaitCallback(ThreadPoolFunc), 10);
        Thread.Sleep(1000);
        ThreadPool.QueueUserWorkItem(new WaitCallback(ThreadPoolFunc), 10.2d);
        Thread.Sleep(1000);
    }
Beispiel #35
0
 public void start及びstopしてisRunnigの状態を確認する_負荷テスト()
 {
     //setUp
     var sut = new MyThread();
     //exercise verify
     for (var i = 0; i < 5; i++){
         sut.Start();
         Assert.That(sut.ThreadBaseKind, Is.EqualTo(ThreadBaseKind.Running));
         sut.Stop();
         Assert.That(sut.ThreadBaseKind, Is.EqualTo(ThreadBaseKind.After));
     }
     //tearDown
     sut.Dispose();
 }
Beispiel #36
0
    static void Main()
    {
        // Notice that the iteration count is passed
        // to these two MyThread objects.
        MyThread mt  = new MyThread("Child #1", 5);
        MyThread mt2 = new MyThread("Child #2", 3);

        do
        {
            Thread.Sleep(100);
        }while (mt.Thrd.IsAlive | mt2.Thrd.IsAlive);

        Console.WriteLine("Main thread ending.");
    }
Beispiel #37
0
 public SocketConnectClient()
 {
     mOutputBuffer         = new DoubleBuffer <byte[]>();
     mReceiveBuffer        = new DoubleBuffer <SocketPacket>();
     mReceiveThread        = new MyThread("SocketReceive");
     mSendThread           = new MyThread("SocketSend");
     mRecvBuff             = new byte[8 * 1024];
     mInputBuffer          = new StreamBuffer(1024 * 1024);
     mConnectStateLock     = new ThreadLock();
     mSocketLock           = new ThreadLock();
     mReceivePacketHistory = new Queue <string>();
     mHeartBeatTimer       = new MyTimer();
     mNetState             = NET_STATE.NONE;
 }
        private void checkButton_Click(object sender, EventArgs e)
        {
            string sourceFolder      = sourceTextBox.Text;
            string destinationFolder = destinationTextBox.Text;

            if (IsNotEmpty(sourceFolder) && IsNotEmpty(destinationFolder))
            {
                if (!Directory.Exists(sourceFolder))
                {
                    MessageBox.Show("Source folder doesn't exist");
                }
                else if (!Directory.Exists(destinationFolder))
                {
                    MessageBox.Show("Destination folder doesn't exist");
                }
                else
                {
                    checkButton.Enabled = false;

                    AppSetting setting = Settings.Get();
                    setting.SourceFolder      = sourceFolder;
                    setting.DestinationFolder = destinationFolder;
                    Settings.Set(setting);

                    IntPtr windowHandle = this.Handle;

                    MyThread <int> actionthread = MyThread.DoInThread(true, () =>
                    {
                        CheckResult checkResult = CheckDifferences(sourceFolder, destinationFolder);

                        checkButton.ThreadSafe(x => x.Enabled = true);

                        string dialogtext = string.Format("{0} files and {1} will be copied, {2} files and {3} will be deleted, continue?", checkResult.FileCountToCopy, ByteSize.SizeSuffix(checkResult.BytesToCopy), checkResult.FileCountToDelete, ByteSize.SizeSuffix(checkResult.BytesToDelete));

                        DialogResult dialogResult = MessageBox.Show(dialogtext, "Copy Files", MessageBoxButtons.YesNo);
                        if (dialogResult == DialogResult.Yes)
                        {
                            thread = new FileCopyingThread(checkResult.FilesToCopy, windowHandle, checkResult.BytesToCopy, fileCopyLabel, checkResult.FilesToDelete, destinationFolder);
                        }

                        return(0);
                    });
                }
            }
            else
            {
                MessageBox.Show("Choose both folders");
            }
        }
Beispiel #39
0
        private void button10_Click(object sender, EventArgs e)
        {
            stopwatch.Restart();
            nu.Num = 0;
            MyThread myThread = new MyThread();

            myThread.nu = nu;
            for (int i = 0; i < 20; i++)
            {
                BackgroundWorker bw = new BackgroundWorker();
                bw.DoWork += new DoWorkEventHandler(DoThread);
                bw.WorkerSupportsCancellation = true;
                bw.RunWorkerAsync();
            }
        }
    public static void Main()
    {
        Console.WriteLine("Основной поток стартовал.");
        // Создаем три потока.
        MyThread mt1 = new MyThread("Потомок #1");
        MyThread mt2 = new MyThread("Потомок #2");
        MyThread mt3 = new MyThread("Потомок #3");

        do
        {
            Console.Write(".");
            Thread.Sleep(10);
        } while (mt1.count < 10 || mt2.count < 10 || mt3.count < 10);
        Console.WriteLine("Основной поток завершен.");
    }
 static void Main()
 {
     Console.WriteLine("Основной поток начат.");
     // Сконструировать три потока.
     MyThread mtl = new MyThread("Поток #1");
     MyThread mt2 = new MyThread("Поток #2");
     MyThread mt3 = new MyThread("Поток #3");
     do
     {
         Console.Write(".") ;
         Thread.Sleep (100);
     } while (mtl.Thrd.IsAlive &&
             mt2.Thrd.IsAlive &&
             mt3.Thrd.IsAlive);
     Console.WriteLine("Основной поток завершен.");
 }
Beispiel #42
0
        public void Test()
        {
            ThreadClass thread = new ThreadClass();

            //Compare Current Thread Ids
            Assert.IsTrue(ThreadClass.Current().Instance.ManagedThreadId == System.Threading.Thread.CurrentThread.ManagedThreadId);

            //Compare instances of ThreadClass
            MyThread mythread = new MyThread();
            mythread.Start();
            while (mythread.Result == null) System.Threading.Thread.Sleep(1);
            Assert.IsTrue((bool)mythread.Result);

            ThreadClass nullThread = null;
            Assert.IsTrue(nullThread == null); //test overloaded operator == with null values
            Assert.IsFalse(nullThread != null); //test overloaded operator != with null values
        }
 static void Main()
 {
     Console.WriteLine("Основной поток начат.");
     // Сначала сконструировать объект типа MyThread.
     MyThread mt = new MyThread("Потомок #1");
     // Далее сконструировать поток из этого объекта.
     Thread newThrd = new Thread(mt.Run);
     // И наконец, начать выполнение потока.
     newThrd.Start();
     int Count = 0;
     do
     {
         Thread.Sleep(100);
         Console.WriteLine("В основном потоке " + "Count = " + Count);
         Count++;
     } while (mt.Count != 10);
     Console.WriteLine("Основной поток завершен.");
 }
Beispiel #44
0
    public static int Main(String[] args)
    {
        //check if total allocation size is not too much for x86
        //Allocate at most 1700MB on x86 to avoid the risk of getting OOM.
        int ProcCount = Environment.ProcessorCount;
        //if (!Environment.Is64BitProcess && ((AllocPerThreadMB * ProcCount) > 1700))
        {
            s_allocPerThreadMB = 1700 / ProcCount;
        }

        Console.WriteLine("Allocating {0}MB per thread...", s_allocPerThreadMB);

        MyThread t;
        Thread[] threads = new Thread[ProcCount];

        Console.WriteLine("Starting {0} threads...", threads.Length);

        for (int i = 0; i < threads.Length; i++)
        {
            t = new MyThread(i, s_allocPerThreadMB);
            threads[i] = new Thread(t.DoWork);
            threads[i].Start();
        }

        //Wait for tasks to finish
        foreach (Thread _thread in threads)
            _thread.Join();

        Thread.Sleep(100);
        for (int i = 0; i < 3; i++)
        {
            GC.Collect();
            GC.WaitForPendingFinalizers();
            GC.Collect();
        }

        Console.WriteLine("PASSED");
        return 100;
    }
 public RetainedFragment()
 {
     mThread = new MyThread(this);
 }
Beispiel #46
0
 public void Stopは重複しても問題ない()
 {
     //setUp
     var sut = new MyThread();
     var expected = ThreadBaseKind.After;
     //exercise
     sut.Stop(); //重複
     sut.Start();
     sut.Stop();
     sut.Stop(); //重複
     var actual = sut.ThreadBaseKind;
     //verify
     Assert.That(actual, Is.EqualTo(expected));
     //tearDown
     sut.Dispose();
 }
Beispiel #47
0
        private static void InitThread()
        {
            //delegate
            MyThread.LogErrorHandler = Console.WriteLine;
            DelayActionProcessor.LogErrorHandler = Console.WriteLine;
            DelayActionProcessor.LogInfoHandler = Console.WriteLine;

            mTaskDispatcher = new MyTaskDispatcher(3, true);
            mTaskDispatcher.DispatchAction(TestThread, "this is a param!");

            mThread = new MyThread();
            mThread.Start();
            mThread.QueueAction(TestThread, "this is a param!");

            //thread.Stop();
        }