![]() |
|
#1
|
|||
|
|||
Thread Stopping ExceptionHi,
I am making this server program that collects info from PCs from around a network when they are active. After having many problems solved by the help of you guys I am trying now with my biggest problem... OK. I have a thread: CPP / C++ / C Code:
and in my function WaitForPackets I have this part of a code: CPP / C++ / C Code:
Basically, I have made a PC class (I can post the code of this one too if needed but I think it is not) and I want to put every new instance of a PC in an array of PCs so that I can refer to if needed in the program. My Unhandled exception (Thread is being stopped) occurs when I create the PC* Comp = new... Can you please give me an idea of how to correct this one, and / or if you think I can do this another way (not with array of objects etc.)? Thanks a lot guys you've been very helpful, Gix |
|||
|
#2
|
|||
|
|||
Re: Thread Stopping ExceptionQuote:
This is invalid. It looks like you are trying to declare an array of pointers to PC, but you didn't give the size of the array. (No compiler should accept this.) If you want an array of pointers, consider the following. I have made my own simple class for purposes of illustration. CPP / C++ / C Code:
CPP / C++ / C Code:
Identical output. Regards, Dave Last edited by davekw7x : 26-Nov-2006 at 09:33.
|
|
#3
|
|||
|
|||
Re: Thread Stopping ExceptionThanks for the help, but when I initialize the array like this:
CPP / C++ / C Code:
I get this errors: error C2691: 'PC' : invalid type for __gc array element error C3149: 'PC' : illegal use of managed type 'PC'; did you forget a '*'? error C2691: 'PC __gc *' : invalid type for __gc array element error C2845: '[' : cannot perform pointer arithmetic on __gc pointer 'PC __gc *' That's why I was doing it the other way: CPP / C++ / C Code:
But my question is that I get an exception in the code... that the thread called is being stopped each time I create the PC object, thus not letting the other part of the code to run properly... Can you please check this, the code is in my first post? Thank you, Gix |
|
#4
|
|||
|
|||
Re: Thread Stopping ExceptionQuote:
1. Your original post in this thread didn't indicate that PC was a __gc class. 2. Your original post had this:PC *Comps[];, not PC *Comps[200];. 3. I still stand by my opinion that your statement PC *Comps[]; should be invalid. Apparently the compiler takes it to mean PC **Comps, which is not the same thing at all. If that is what the compiler means, then the value is not initialized and the exception is caused when your assignment dereferences it. That is, if **Comps is equal to zero, then Comps[i] is illegal, since it tries to get someting from address zero. (I believe that the exception was caused by the assignment, not the instantiation.) You could save some time if you make absolutely clear what you are working on. (The fact that a previous thread was about __gc classes doesn't mean that everyone understands what this one is about. Not everyone even read the old thread. I read the old thread, but did not understand that this one was about __gc classes. Other things coming into my mind crowd out the older things. Even if I had remembered your previous question, I would not automatically assume that you were talking about the same data type.) Quote:
CPP / C++ / C Code:
Back to my example: One thing you are right about, __gc objects are pointers, so an array of __gc objects is an array of pointers. CPP / C++ / C Code:
Output: Code:
You don't need a separate object Comp, you could allocate and assign in one step: CPP / C++ / C Code:
Regards, Dave |
|
#5
|
|||
|
|||
Re: Thread Stopping ExceptionOK. Sorry for not being clear in the first place.
Second, yes... I am talking about a __gc class, and again sorry for not mentioning this ( I take some things for granted, my bad ) Now let me answer your questions so that you can further help me if you can. 1. Yes. PC is a __gc class. 2. I am still initializing the array like this: CPP / C++ / C Code:
like in your example: Quote:
I do this because it is the only way the compiler accepts it. 3. OK here I'll try to make my question clearer... This is my thread: CPP / C++ / C Code:
Now in my WaitForPackets function that it calls upon I have this line of code that generates the exception during runtime: CPP / C++ / C Code:
so it is not the array that is the problem that causes the exception, but it is the creation of this new object of the __gc class PC. I hope now I got it clearer. Thank you for trying so hard to help me again, Gix |
|
#6
|
|||
|
|||
Re: Thread Stopping ExceptionQuote:
Well, I didn't mean to sound snippy. Sometimes my responses sound a little more curt than I really mean them to be. Quote:
Put the following statement in your program and tell me what it says: CPP / C++ / C Code:
If it says Comps = 0 then it won't work Did you try CPP / C++ / C Code:
We are using different versions of compilers (and it is possible that the bugs in yours are different from the bugs in mine), and If your compiler won't accept this, then I have reached the end of our journey together, if not the end of the road altogether. That's just about the only way that I can think of to get an array of __gc objects. Actually I guess that you can separate the statements like this: CPP / C++ / C Code:
But without actually allocating memory for the array, I don't see how you can ever expect to use it (regardless of other problems with the code). Quote:
How do you know? (I am not challenging your assertion; I just want to know.) Did you step through with a debugger? Did you put print statements just before and just after the object instantiation? Or What? Whatever method you used to track down the bad behavior to this point: use the same method to go farther into it. Since I have no idea what the constructor is doing with its arguments and I have no idea what the argument values are, I am at a loss. (I doubt that I would be able to get more out of additional code, since there is, obviously, a lot of it.) Depending on what you have done so far, maybe you can print out the values of aguments, or at least make sure that the program is working on what you think it should be working on. Or maybe you can go into the constructor and put debug statements to print out the progress through the statements there. (Or, better yet, if you can step through the code with a debugger, you can find the actual place that causes the exception and see what's happening at that exact place in the code.) Regards, Dave |
|
#7
|
|||
|
|||
Re: Thread Stopping ExceptionQuote:
No problem. Quote:
You are correct here... I didn't really think about this when writing my code and I corrected it now. Now about my REAL tough problem! I know that the pointed line causes the exception because I run it with a debugger and I put breakpoints through the code... The program crashes when it reaches the creation of the PC Object... It doesn't even enter inside the constructor of the class, but dialogs out the following message: Quote:
Then I hit Break or Continue and that's it... none of the code was executed from there on... |
|
#8
|
|||
|
|||
Re: Thread Stopping ExceptionQuote:
My final desperate suggestion: Have you tried running it as Release, not Debug (put print statements before and after the creation line). Even having your complete code probably wouldn't help, since I don't have your environment. Sorry. Regards, Dave Last edited by davekw7x : 26-Nov-2006 at 16:24.
|
|
#9
|
|||
|
|||
Re: Thread Stopping ExceptionQuote:
If it's not a language thing (and I'm beginning to think it is not), then it's an application thing. Do your child threads try to change the User Interface? Could that be a problem? (Have you run anything like this before? In Debug mode?) Regards, Dave |
|
#10
|
|||
|
|||
Re: Thread Stopping ExceptionDISREGARD THIS POST... SORRY FOR DOUBLE POST
Hi again... There has been a development in this problem of mine... So now I run the program (debug mode) and instead of usting the previous constructor I use this: CPP / C++ / C Code:
The default constructor. And there is no exception and everything runs smoothly, the exception happens when I use the other constructor... Now I am going to paste the class PC here, can you please tell me if you see anything wrong in the constructor PC(String* BT, String*, .... ..., int AN): CPP / C++ / C Code:
Thanks again, Gix |
Recent GIDBlog
Vista ?Widgets? on Windows XP by LocalTech
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Thread | itch | C++ Forum | 7 | 10-May-2006 15:10 |
| please help in solving: Exception in thread "main" java.lang.nullpointerexception | vkiran_v | Java Forum | 8 | 09-May-2006 07:06 |
| C++ Copy Constructor & Exception issues | greymalkin | C++ Forum | 3 | 05-Oct-2005 21:36 |
| Sending message to GUI thread that ISNT the main thread | mpviii | MS Visual C++ / MFC Forum | 1 | 20-Apr-2005 12:49 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The