Thread: Threading VS 2005

  1. #1
    Registered User
    Join Date
    Nov 2006
    Posts
    6

    Threading VS 2005

    OK, I'm using VS 2005 and I am having a difficult Time in creating and starting a thread. Below is my code that should start a thread, but the last output on the debugger says "A first chance exception of type 'System.IndexOutOfRangeException' occurred in FTPClient.exe" and the process doesn't kick off.
    Code:
    private void Form1_Load(object sender, EventArgs e)
    {
          Thread newThread = new Thread(LoadConfig);
           newThread.Start();
    }
    The below code is what I wrote in C# VS 2003 and it works.
    Code:
    Thread newThread =  new Thread(new ThreadStart(Go));
    newThread.Start();
    Any answers or ideas are greatly appreciated.

    Thanks,
    Josh

  2. #2
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    Hmm... I don't know threads outside Boost::threads... But that new statement is plain and vanilla C++:

    Code:
    Thread* newThread = new Thread(LoadConfig);
    If that alone will solve your problem, I don't know. But you need a pointer to allocate memory.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  3. #3
    Registered User
    Join Date
    Nov 2006
    Posts
    6
    Throws a lot of errors when I use the pointer.
    Error 1 Cannot take the address of, get the size of, or declare a pointer to a managed type ('System.Threading.Thread')
    Error 2 Pointers and fixed size buffers may only be used in an unsafe context
    Error 3 Cannot implicitly convert type 'System.Threading.Thread' to 'System.Threading.Thread*'
    Error 4 Pointers and fixed size buffers may only be used in an unsafe context
    Error 5 Operator '.' cannot be applied to operand of type 'System.Threading.Thread*'

    Thanks,
    Josh

  4. #4
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    More errors doesn't mean necessarily it's more wrong
    I had it happen to me before.

    However, I can see you are using managed C++. My bad. Forgot about this forum theme.

    It's thread^, I reckon. Not *. The last error message has to do with the need to use the -> operator when accessing members of of a pointer to object. I don't know if that syntax remains in managed C++.

    Anyways, since this is managed C++... I'm kind out of my environment. So, over and out. Hope that at least leads you in the right direction
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  5. #5
    Registered User C of Green's Avatar
    Join Date
    Jan 2002
    Location
    Calgary/Canada
    Posts
    59
    you can try something like this ...

    Code:
                Thread newThread = new Thread(new ThreadStart(doSomething));
                newThread.Start();

  6. #6
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Mario, this is C#, not Managed C++. You stumbled into the C# forum

    Do you have a stack trace with that exception?
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  7. #7
    Registered User C of Green's Avatar
    Join Date
    Jan 2002
    Location
    Calgary/Canada
    Posts
    59
    oh sorry i didnt see this ...


    The below code is what I wrote in C# VS 2003 and it works.
    Code:

    Thread newThread = new Thread(new ThreadStart(Go));
    newThread.Start();
    however ... seems you might have an array out of index in "LoadConfig" or elsewhere ...


    System.IndexOutOfRangeException

  8. #8
    Registered User C of Green's Avatar
    Join Date
    Jan 2002
    Location
    Calgary/Canada
    Posts
    59

    Throws a lot of errors when I use the pointer.
    you can use the "unsafe" keyword to use pointers ...

    Code:
        class Program
        {
                unsafe public void test()
                {
                    int* pointer;
                    int digit = 100;
                    pointer = &digit;
                    Console.WriteLine("{0}", pointer);
                }
    
            static void Main(string[] args)
            {
                test();
            }
        }
    just make sure you "allow" it in your complier options

  9. #9
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    That is not the point, however. Unsafe code is, well, unsafe, and underlies many restrictions, as do programs that use it.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  10. #10
    Registered User C of Green's Avatar
    Join Date
    Jan 2002
    Location
    Calgary/Canada
    Posts
    59

    That is not the point, however. Unsafe code is, well, unsafe, and underlies many restrictions, as do programs that use it.
    ya well, a comment was made about pointers and i just simply made a reply, and "unsafe" code was added to c# for a reason like performance, flexibility and direct memory management. I think c# would be a weaker language without them.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. stdin in Visual Studio 2005 vs. 2003
    By Trev614 in forum C Programming
    Replies: 5
    Last Post: 06-23-2008, 02:44 PM
  2. Task list in VC 2005
    By VirtualAce in forum Tech Board
    Replies: 0
    Last Post: 05-13-2008, 08:59 PM
  3. If you must port to .NET 2005, read this thread.
    By VirtualAce in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 10-22-2007, 06:51 AM
  4. Warning to all those wishing to port to .NET 2005
    By VirtualAce in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 05-07-2006, 09:29 PM
  5. Really basic string operation
    By bobthebullet990 in forum C Programming
    Replies: 6
    Last Post: 11-28-2005, 05:18 PM