locked
Using .invoke in a thread RRS feed

  • Question

  • gud day,

    i do have developeed a simple mobile chat application that has a message archive that will be stored in my database.. i do have successfully finished the sending and recieving of messages.

     my problem comes in when i open the message archive form and go back to the main form. the application doesn't write any string message on the textbox. i do have tried to check if the string message was succesfully passed on the method that will show the string and the result is ok by displaying it on a messagebox.  i'm using a singleton for the instances of my form. 

    i think my proble is the usage of the invoke..

    this is my code

    private static string strHolder;
    private delagate void UpdateTextBox;

    public void UpdateTextBox()
    {
    txtRecieve.Text+=strHolder;
    }

    private void RecieveLoop()
    {
    //listening
    strRecieve=recieveMessage();
    if(strRecieve!="")
    {
    txtRecieve.Invoke(new UpdateTextBox(this.UpdateTextBox));
    }
    }

    private void Main_Load()
    {
    thread t= new thread(receiveloop);
    t.start();
    }


    any comments and suggestion is much appreciated.
    Thursday, September 24, 2009 7:35 AM

Answers

  • Hi,

     

    If I am not mistaking, I failed to see a loop in your function

    private void RecieveLoop()

    {

    //listening

    strRecieve=recieveMessage();

    if(strRecieve!="")

    {

    txtRecieve.Invoke(new UpdateTextBox(this.UpdateTextBox));

    }

    }

    I guessed you receiveMessage() function is implemented based on some block-waiting mechanism, if so it should be placed in a while(true) loop.

     

    Hope this helps,

    Zhe Zhao

     

     

     

    • Marked as answer by ZHE ZHAO Wednesday, September 30, 2009 3:22 AM
    Monday, September 28, 2009 3:00 AM

All replies

  • Hi,

    Are you getting any error or exception?

    Regards,
    Malleswar
    Thursday, September 24, 2009 10:07 AM
  • i haven't getting any exception or any error.. but the string failed to be shown on to the textbox. after shifting forms... at first the recieve string can be shown. but after i go to another form and return to the main form, the string cannot be shown anymore into the textbox.

    any ideas??
    Thursday, September 24, 2009 10:44 AM
  • Hi,

     

    If I am not mistaking, I failed to see a loop in your function

    private void RecieveLoop()

    {

    //listening

    strRecieve=recieveMessage();

    if(strRecieve!="")

    {

    txtRecieve.Invoke(new UpdateTextBox(this.UpdateTextBox));

    }

    }

    I guessed you receiveMessage() function is implemented based on some block-waiting mechanism, if so it should be placed in a while(true) loop.

     

    Hope this helps,

    Zhe Zhao

     

     

     

    • Marked as answer by ZHE ZHAO Wednesday, September 30, 2009 3:22 AM
    Monday, September 28, 2009 3:00 AM