locked
How to handle long running process ? RRS feed

  • Question

  • User998918640 posted

    for example:

    dim a as long

    for i as integer = 1 to 10000000

         for t as integer = 1 to 10000000

              a = a + 1

         next

    next

    it will hang when it run til half way, can anyone help me to slove this problem ??

    Friday, July 6, 2012 2:37 AM

Answers

  • User2019981500 posted

    I have got some example which use multiple thread for reading long running processes just run it and see.you can convert it to vb.net also

      static void Main(string[] args)
            {
                Console.Write("How many iterations in total? ");//for you it 10000000
                int totalIterations = Int32.Parse(Console.ReadLine());
                Console.Write("How many threads? ");
                int totalThreads = Int32.Parse(Console.ReadLine());
                // So how many iterations per thread? (This is just for example, it will get 1 more than required in some cases)
                int iterationsPerThread = (int)Math.Ceiling((double)(totalIterations / totalThreads));
                ParameterizedThreadStart threadStart = new ParameterizedThreadStart(threadProcess);
                for (int i = 0; i < totalThreads; i++)
                {
                    Thread t = new Thread(threadStart);
                    t.Start(new[] { i, iterationsPerThread });
                }
                Console.ReadLine();
            }
            static void threadProcess(object o)
            {
                int ThreadNum = ((int[])o)[0];
                int Iterations = ((int[])o)[1];
    
                for (int i = 0; i < Iterations; i++)
                {
                    for (int t = 0; i < Iterations; i++)
                    {
                        Console.WriteLine("Thread " + ThreadNum + ": On iteration " + i);
                    }
                }
    
            }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, July 6, 2012 3:25 AM