c# multithreading

Discussion in 'Software' started by mastermosley, Mar 6, 2009.

  1. mastermosley

    mastermosley Sergeant

    I need a safe way to pass information from a thread to the main thread in which my UI was created in. I need a textbox to receive information and display it while on a different thread.

    Code:
    //I added a public delegate to the main form class
    public delegate void UpdateTextCallback(string message);
    
    //then an invoke function
            public void InvokeUI(string linetoadd)
            {
                txtServerStatus.BeginInvoke(new UpdateTextCallback(AddToText));
                
            }
    
    I just get a InvalidOperationException was unhandled error

    I read the help and it says its a warning because its unsafe to access a UI element from a different thread then what it was created on so is there a way to pass the string to the main ui thread and have it invoke the textbox, instead of having the other thread invoke it.
     
  2. PC-XT

    PC-XT Master Sergeant


MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds