c# - Lidgren - InvalidOperationException was unhandled -


argh! i'm back, guys! hate having bother others issues, i've been working on 3 days now.

using chat application example, molded game. client , server connect appropriately but... client having trouble. :/

    public static void appendtext(richtextbox box, string line)     {         if (box == null || box.isdisposed)             return;         //try         //{             box.appendtext(line + environment.newline);             scrollrichtextbox(box);         //}         //catch         //{         //    program.debug.print("something went wrong.");         //}     } 

the appendtext line keeps throwing exception (invalidoperationexception). commented out try-catch, hoping compiler give me more advice on what's wrong , maybe how fix it, no help.

in examples, can run code without getting error. don't know went wrong here.

oh, appendtext called by...

    public static void gotmessage(object peer)     {         netincomingmessage im;         while ((im = s_client.readmessage()) != null)         {             // handle incoming message             switch (im.messagetype)             {                 case netincomingmessagetype.debugmessage:                 case netincomingmessagetype.errormessage:                 case netincomingmessagetype.warningmessage:                 case netincomingmessagetype.verbosedebugmessage:                     string text = im.readstring();                     //textcontrol.appendtext(menuwindow.richtextboxstatus, text);                     program.printstatus(text);                     break;                  case netincomingmessagetype.statuschanged:                     netconnectionstatus status = (netconnectionstatus)im.readbyte();                      /*if (status == netconnectionstatus.connected)                         s_form.enableinput();                     else                         s_form.disableinput();                     */                      //if (status == netconnectionstatus.disconnected)                         //s_form.button2.text = "connect";                      string reason = im.readstring();                     program.printstatus(status.tostring() + ": " + reason);                     break;                  case netincomingmessagetype.data:                     // incoming packet server, handle data                     int size = im.readint32();                     byte[] bdata = im.readbytes(size);                      string data = encoding.unicode.getstring(bdata);                      program.debug.print(data);                     program.printtochat(data);                     handledata(data);                      break;                  default:                     program.printstatus("unhandled type: " + im.messagetype + " " + im.lengthbytes + " bytes");                     break;             }            }     } 

where printtochat or printstatus found. methods contain calls appendtext.

i tried post lidgren google group when error first popped up, haven't gotten response them, i'm hoping people here have information seek. :)

i can provide more information , code if needed (as always, heh).

(i did google how make thread-safe calls ui elements, code confusing comprehend. when thought implemented solution, refused work @ all..)

pfft, @ me, figuring things out.

i able add delegate methods forms can access across threads. or i'm led believe. code functions intended.

i coooould add code, show did. , if needs type of problem. think i'm capable of explaining it, msdn works wonders.

as always, had ask question, , read comments led in right direction.

i need stop asking questions end answering days later. :/

i'm sooo sorry. feel bad taking space , wasting time.

edit: i've written clever way of circumventing needing use delegates. however, requires use of timer, or loop repaints windows form every , (i've used timer).


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -