CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: Multi Threading

  1. #1
    Join Date
    Feb 2008
    Posts
    14

    Multi Threading

    i declare a thread which runs a Sub that just opens up a loading screen while
    a query is run on the OS thread. i want to close the loading thread when the
    query is done but without using thread.abort(). anyone let me know if there is
    a way to do this. If not, i would be ok with using thread.abort() as i dont care
    about losing anything from the loading thread because all it does is display a
    form on the screen. but i keep getting the ThreadAbortException "Thread was
    being aborted" error. so if anyone can help me to hide this error i would really
    appreciate it. thanks

  2. #2
    Join Date
    Aug 2005
    Location
    Spain!
    Posts
    149

    Wink Re: Multi Threading

    Hi!, here's some useful information about threads, its in C#, but is easy to understand the basics.

    http://www.yoda.arachsys.com/csharp/threads/

    As i can remember, when a thread has nothing to do, it ends, so with your call to Abort you're forzing to exit and give an exception to show you why it has been closed.

    Hope this information is useful to you

  3. #3
    Join Date
    Feb 2008
    Posts
    14

    Re: Multi Threading

    thanks for the reply. However the problem is have is that the thread will never stop itself because it is dependent on the OS thread. So i need to abort() the declared thread depending on OS thread. but the ThreadAbortException gets thrown whenever you use Abort(), even if you have a Try Catch on it. I just need to figure out how to not show the error, cause i cant get that to work.
    thanks alot, i appreciate any help

  4. #4
    Join Date
    Mar 2007
    Location
    Argentina
    Posts
    579

    Re: Multi Threading

    Quote Originally Posted by satanorz
    Hi!, here's some useful information about threads, its in C#, but is easy to understand the basics.

    http://www.yoda.arachsys.com/csharp/threads/
    ...
    Interesting Link. I want to start learning about multithreading, so, I want to translate the code to VB.net.

    This c# code I had get from that link:
    Code:
    using System;
    using System.Threading;
    
    public class Test
    {
        static void Main()
        {
            Counter foo = new Counter();
            ThreadStart job = new ThreadStart(foo.Count);
            Thread thread = new Thread(job);
            thread.Start();
            
            for (int i=0; i < 5; i++)
            {
                Console.WriteLine ("Main thread: {0}", i);
                Thread.Sleep(1000);
            }
        }
    }
    
    public class Counter
    {
        public void Count()
        {
            for (int i=0; i < 10; i++)
            {
                Console.WriteLine ("Other thread: {0}", i);
                Thread.Sleep(500);
            }
        }
    }
    have the "using" statement. ¿Is correct to translate it to VB.NET as the "Implements" statement?

  5. #5
    Join Date
    Aug 2005
    Location
    Spain!
    Posts
    149

    Wink Re: Multi Threading

    Hi!, i think that the correct translation to VB.NET will be

    Code:
    Imports System;
    Imports System.Threading;

  6. #6
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,284

    Re: Multi Threading

    There's also a free online C# to VB.NET converter :
    http://labs.developerfusion.co.uk/co...arp-to-vb.aspx

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured