Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all

Okay, this must be some kind of monkeytest, but I just dont get it.

I have WPF UI where I have richtextbox "myLog". Also I get data now and then which could need logging. When my event call my Log method I receive error:

"The calling thread cannot access this object because a different thread owns it"

And here is simplified idea of my logmethod:

//LogMsgType msgtype: Error/Incoming/Normal/Outgoing,Warning , string msg: message 
private void Log(LogMsgType msgtype, string msg)
        {
        myLog.AppendText(msg); //here error occurs 
        }


i really appreciate your advices :)
Posted

1 solution

You need to do an Invoke() here because the textbox is owned by a different thread than the one trying to update it.

This should point you in the right direction:

http://www.codeproject.com/KB/threads/winformsthreading.asp[^]
 
Share this answer
 
v2
Comments
paleGegg0 13-Nov-10 3:41am    
Thank you! That article solved my problem :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900