Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Ugly error

Ugly error

Scheduled Pinned Locked Moved C#
helplounge
18 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    nc3b
    wrote on last edited by
    #1

    Ok here's the error I am making a chat client. The user has to open a new windows for each client he wants to talk to. So if he clicks the button if(TO[TOS[this.listBox1.SelectedIndex]].Visible) { TO[TOS[this.listBox1.SelectedIndex]].Focus(); } else { TO[TOS[this.listBox1.SelectedIndex]].Show(); } I use that and it works. But I also want the program to open a window when it receives data from a client who's window is not opened(just like Yahoo Messenger). if(TO[num].Visible) { TO[num].Receive(Got.Split(":".ToCharArray(),2)[1]); } else { TO[num].Show(); TO[num].Receive(Got.Split(":".ToCharArray(),2)[1]); } And then i get something like the left-over of a window and the program exits, without pointing out an exceptio at least. Please help.:sigh: -- modified at 2:57 Tuesday 31st January, 2006

    V I 2 Replies Last reply
    0
    • N nc3b

      Ok here's the error I am making a chat client. The user has to open a new windows for each client he wants to talk to. So if he clicks the button if(TO[TOS[this.listBox1.SelectedIndex]].Visible) { TO[TOS[this.listBox1.SelectedIndex]].Focus(); } else { TO[TOS[this.listBox1.SelectedIndex]].Show(); } I use that and it works. But I also want the program to open a window when it receives data from a client who's window is not opened(just like Yahoo Messenger). if(TO[num].Visible) { TO[num].Receive(Got.Split(":".ToCharArray(),2)[1]); } else { TO[num].Show(); TO[num].Receive(Got.Split(":".ToCharArray(),2)[1]); } And then i get something like the left-over of a window and the program exits, without pointing out an exceptio at least. Please help.:sigh: -- modified at 2:57 Tuesday 31st January, 2006

      V Offline
      V Offline
      Vikram A Punathambekar
      wrote on last edited by
      #2

      Did you put a breakpoint and step through the part where it gives you problems? If you can find out which line breaks your code, it might be easier to fix it. Cheers, Vikram.


      "When I read in books about a "base class", I figured this was the class that was at the bottom of the inheritence tree. It's the "base", right? Like the base of a pyramid." - Marc Clifton. i dont mind to be a stupid,better than being a moron - Adnan Siddiqi.

      N 1 Reply Last reply
      0
      • V Vikram A Punathambekar

        Did you put a breakpoint and step through the part where it gives you problems? If you can find out which line breaks your code, it might be easier to fix it. Cheers, Vikram.


        "When I read in books about a "base class", I figured this was the class that was at the bottom of the inheritence tree. It's the "base", right? Like the base of a pyramid." - Marc Clifton. i dont mind to be a stupid,better than being a moron - Adnan Siddiqi.

        N Offline
        N Offline
        nc3b
        wrote on last edited by
        #3

        Really, I'll try, altough until now I haven't used this method

        N 1 Reply Last reply
        0
        • N nc3b

          Really, I'll try, altough until now I haven't used this method

          N Offline
          N Offline
          nc3b
          wrote on last edited by
          #4

          :( Ok, It managed to jam the debugger. I am speechless :(

          C 1 Reply Last reply
          0
          • N nc3b

            :( Ok, It managed to jam the debugger. I am speechless :(

            C Offline
            C Offline
            Colin Angus Mackay
            wrote on last edited by
            #5

            nc3b wrote:

            It managed to jam the debugger

            What do you mean by that? How did it "jam" the debugger? ColinMackay.net "Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucius "If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell

            N 1 Reply Last reply
            0
            • C Colin Angus Mackay

              nc3b wrote:

              It managed to jam the debugger

              What do you mean by that? How did it "jam" the debugger? ColinMackay.net "Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucius "If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell

              N Offline
              N Offline
              nc3b
              wrote on last edited by
              #6

              Simple. I caused it to crash :sigh:

              C 1 Reply Last reply
              0
              • N nc3b

                Ok here's the error I am making a chat client. The user has to open a new windows for each client he wants to talk to. So if he clicks the button if(TO[TOS[this.listBox1.SelectedIndex]].Visible) { TO[TOS[this.listBox1.SelectedIndex]].Focus(); } else { TO[TOS[this.listBox1.SelectedIndex]].Show(); } I use that and it works. But I also want the program to open a window when it receives data from a client who's window is not opened(just like Yahoo Messenger). if(TO[num].Visible) { TO[num].Receive(Got.Split(":".ToCharArray(),2)[1]); } else { TO[num].Show(); TO[num].Receive(Got.Split(":".ToCharArray(),2)[1]); } And then i get something like the left-over of a window and the program exits, without pointing out an exceptio at least. Please help.:sigh: -- modified at 2:57 Tuesday 31st January, 2006

                I Offline
                I Offline
                Ingo
                wrote on last edited by
                #7

                Hi! First I would use a 'try-catch' just like: try { -your code- } catch (Exception expt) { System.Windows.Forms.MessageBox.Show(expt.ToString()); } // try-catch The Next Point is that inline-code is easy to programm but hard to debug, so it's no good style to do everytrhing in a single line. So split your code: string[] strArrayGot = Got.Split(":".ToCharArray(),2); TO[num].Receive(strArrayGot[1]); The next thing you have todo is watch your debugger. Then you can find out where the program exists. I just talk about your variable names. But its hard to read. What the hell is TO and what about TOS? And listBox1 isn't a good name, too. What is handled there? The Number '1'? Ok, you can programm that way, but it's hard to read and hard to find errors, so you should try to code a little bit more readable. Hope I didn't dumbfounded you, was just an idea. Greetings, Ingo -- modified at 4:47 Tuesday 31st January, 2006

                N 1 Reply Last reply
                0
                • N nc3b

                  Simple. I caused it to crash :sigh:

                  C Offline
                  C Offline
                  Colin Angus Mackay
                  wrote on last edited by
                  #8

                  How can you expect help when you make vague statements like this. What were the manifestations of the crash? By "jam" it suggests that maybe it hung. You also mentioned you were unused to setting breakpoints. Perhaps you mistook the breakpoint hitting for a hanging application, because that is essentially what it does. ColinMackay.net "Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucius "If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell

                  N 1 Reply Last reply
                  0
                  • C Colin Angus Mackay

                    How can you expect help when you make vague statements like this. What were the manifestations of the crash? By "jam" it suggests that maybe it hung. You also mentioned you were unused to setting breakpoints. Perhaps you mistook the breakpoint hitting for a hanging application, because that is essentially what it does. ColinMackay.net "Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucius "If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell

                    N Offline
                    N Offline
                    nc3b
                    wrote on last edited by
                    #9

                    In deed I am unused with breakpoints, but I got that nice old error message, asking me if I want to send the error to microsoft..

                    C 1 Reply Last reply
                    0
                    • N nc3b

                      In deed I am unused with breakpoints, but I got that nice old error message, asking me if I want to send the error to microsoft..

                      C Offline
                      C Offline
                      Colin Angus Mackay
                      wrote on last edited by
                      #10

                      Fair enough - but, if you'd said that to start with then we wouldn't have needed this exchange to determine that. ColinMackay.net "Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucius "If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell

                      1 Reply Last reply
                      0
                      • I Ingo

                        Hi! First I would use a 'try-catch' just like: try { -your code- } catch (Exception expt) { System.Windows.Forms.MessageBox.Show(expt.ToString()); } // try-catch The Next Point is that inline-code is easy to programm but hard to debug, so it's no good style to do everytrhing in a single line. So split your code: string[] strArrayGot = Got.Split(":".ToCharArray(),2); TO[num].Receive(strArrayGot[1]); The next thing you have todo is watch your debugger. Then you can find out where the program exists. I just talk about your variable names. But its hard to read. What the hell is TO and what about TOS? And listBox1 isn't a good name, too. What is handled there? The Number '1'? Ok, you can programm that way, but it's hard to read and hard to find errors, so you should try to code a little bit more readable. Hope I didn't dumbfounded you, was just an idea. Greetings, Ingo -- modified at 4:47 Tuesday 31st January, 2006

                        N Offline
                        N Offline
                        nc3b
                        wrote on last edited by
                        #11

                        Ok, there's no secret about it. TO is an array of forms, TOS is an array of integers. So when I try to open a new form, first i must know which form to try to open. It's part of a dumb mechanism. My problem is with num. I am SURE I am not trying to open the wrong form, but I want to ask you, could the rest of the function that calls TO[num].Show() be the problem? And by the way, my program is full of try-catch but you see, this error doesn't throw any exception, it displays a part of the form it should display and it stops working. Then I get that nice message about sending the report and I wonder if microsoft's coders want to help me solve the problem... :)

                        I N 2 Replies Last reply
                        0
                        • N nc3b

                          Ok, there's no secret about it. TO is an array of forms, TOS is an array of integers. So when I try to open a new form, first i must know which form to try to open. It's part of a dumb mechanism. My problem is with num. I am SURE I am not trying to open the wrong form, but I want to ask you, could the rest of the function that calls TO[num].Show() be the problem? And by the way, my program is full of try-catch but you see, this error doesn't throw any exception, it displays a part of the form it should display and it stops working. Then I get that nice message about sending the report and I wonder if microsoft's coders want to help me solve the problem... :)

                          I Offline
                          I Offline
                          Ingo
                          wrote on last edited by
                          #12

                          Ok sounds good. So TO[num] is available and not null?! the string you give to receive(...) is ok? Then I see the problem, if you thought to check this. The programm should work, but it doesn't. I got a similar error a few weeks ago. The application crushed while calling a method of an object which was definitivly ok. The solution - sound strange - was to build the project new. I started with an empty projectmap, added empty projects, copied the forms and classes in the directory added each class and compiled again. After that the programm runned whithout any mistake (did I mentioned that I hate .Net? ;) ) ! Greetings, Ingo

                          1 Reply Last reply
                          0
                          • N nc3b

                            Ok, there's no secret about it. TO is an array of forms, TOS is an array of integers. So when I try to open a new form, first i must know which form to try to open. It's part of a dumb mechanism. My problem is with num. I am SURE I am not trying to open the wrong form, but I want to ask you, could the rest of the function that calls TO[num].Show() be the problem? And by the way, my program is full of try-catch but you see, this error doesn't throw any exception, it displays a part of the form it should display and it stops working. Then I get that nice message about sending the report and I wonder if microsoft's coders want to help me solve the problem... :)

                            N Offline
                            N Offline
                            nc3b
                            wrote on last edited by
                            #13

                            :sigh: The solution to the problem remains illusive... please if anyone can help me... I wonder if the problem is that I am calling TO[num].Show() from public void OnReceive(IAsyncResult ar), now is have to go...

                            I S 2 Replies Last reply
                            0
                            • N nc3b

                              :sigh: The solution to the problem remains illusive... please if anyone can help me... I wonder if the problem is that I am calling TO[num].Show() from public void OnReceive(IAsyncResult ar), now is have to go...

                              I Offline
                              I Offline
                              Ingo
                              wrote on last edited by
                              #14

                              I don't think so. Why should there be a problem. It's just an event. But you can find out. Don't show the form, start a timer instead, then from the timer-event you can show the form after e.g. 100 ms. If that works, you got the problem, if it doesn't work you know that this isn't the problem. Greetings, Ingo

                              N 2 Replies Last reply
                              0
                              • I Ingo

                                I don't think so. Why should there be a problem. It's just an event. But you can find out. Don't show the form, start a timer instead, then from the timer-event you can show the form after e.g. 100 ms. If that works, you got the problem, if it doesn't work you know that this isn't the problem. Greetings, Ingo

                                N Offline
                                N Offline
                                nc3b
                                wrote on last edited by
                                #15

                                Ok, I am finally home and I am going to try the timer thing...

                                1 Reply Last reply
                                0
                                • I Ingo

                                  I don't think so. Why should there be a problem. It's just an event. But you can find out. Don't show the form, start a timer instead, then from the timer-event you can show the form after e.g. 100 ms. If that works, you got the problem, if it doesn't work you know that this isn't the problem. Greetings, Ingo

                                  N Offline
                                  N Offline
                                  nc3b
                                  wrote on last edited by
                                  #16

                                  Tried the timer, it simply doesn't trigger. Nothing hasppens. It is incredible. :|

                                  1 Reply Last reply
                                  0
                                  • N nc3b

                                    :sigh: The solution to the problem remains illusive... please if anyone can help me... I wonder if the problem is that I am calling TO[num].Show() from public void OnReceive(IAsyncResult ar), now is have to go...

                                    S Offline
                                    S Offline
                                    S Senthil Kumar
                                    wrote on last edited by
                                    #17

                                    You can't display a form from a threadpool thread (which I think OnReceive is). This[^] article tells you why it's a bad idea to do any UI manipulation from a non UI thread. For your problem, I'd suggest calling Invoke like this

                                    delegate void FormShowDelegate(Form f);

                                    public void OnReceive(IAsyncResult ar)
                                    {
                                    TO[num].Invoke(new FormShowDelegate(ShowForm), new object[]{TO[num]});
                                    }

                                    private void ShowForm(Form f)
                                    {
                                    f.Show();
                                    }

                                    This of course, assumes that you populated the TO[num] array from the UI thread.. Regards Senthil _____________________________ My Blog | My Articles | WinMacro

                                    N 1 Reply Last reply
                                    0
                                    • S S Senthil Kumar

                                      You can't display a form from a threadpool thread (which I think OnReceive is). This[^] article tells you why it's a bad idea to do any UI manipulation from a non UI thread. For your problem, I'd suggest calling Invoke like this

                                      delegate void FormShowDelegate(Form f);

                                      public void OnReceive(IAsyncResult ar)
                                      {
                                      TO[num].Invoke(new FormShowDelegate(ShowForm), new object[]{TO[num]});
                                      }

                                      private void ShowForm(Form f)
                                      {
                                      f.Show();
                                      }

                                      This of course, assumes that you populated the TO[num] array from the UI thread.. Regards Senthil _____________________________ My Blog | My Articles | WinMacro

                                      N Offline
                                      N Offline
                                      nc3b
                                      wrote on last edited by
                                      #18

                                      Thank you verry much. I found out that the function runs in a new thread (or something like that) and to call a function in the main thread I would use invoke a few hours ago. Still, thank you very much, I'm so happy the program works now :D Cheers :)

                                      1 Reply Last reply
                                      0
                                      Reply
                                      • Reply as topic
                                      Log in to reply
                                      • Oldest to Newest
                                      • Newest to Oldest
                                      • Most Votes


                                      • Login

                                      • Don't have an account? Register

                                      • Login or register to search.
                                      • First post
                                        Last post
                                      0
                                      • Categories
                                      • Recent
                                      • Tags
                                      • Popular
                                      • World
                                      • Users
                                      • Groups