डीबगिंग करते समय मुझे निम्न त्रुटि मिलती है।क्रॉस-थ्रेड ऑपरेशन मान्य नहीं है
public void OnDataReceived(IAsyncResult asyn)
{
try
{
SocketPacket socketData = (SocketPacket)asyn.AsyncState;
int iRx = 0;
// Complete the BeginReceive() asynchronous call by EndReceive() method
// which will return the number of characters written to the stream by the client
iRx = socketData.m_currentSocket.EndReceive (asyn);
char[] chars = new char[iRx + 1];
System.Text.Decoder d = System.Text.Encoding.UTF8.GetDecoder();
int charLen = d.GetChars(socketData.dataBuffer, 0, iRx, chars, 0);
System.String szData = new System.String(chars);
richTextBoxReceivedMsg.AppendText(szData);
// Continue the waiting for data on the Socket
WaitForData(socketData.m_currentSocket);
}
catch (ObjectDisposedException)
{
System.Diagnostics.Debugger.Log(0,"1","\nOnDataReceived: Socket has been closed\n");
}
catch (SocketException se)
{
MessageBox.Show(se.Message);
}
}
किसी कृपया मुझे इसे ठीक मदद कर सकते हैं:
Cross-thread operation not valid: Control 'richTextBoxReceivedMsg' accessed from a thread other than the thread it was created on.
यहाँ कोड है कि यह की ओर इशारा करता है? कारण यह है कि Windows Forms वास्तव में अलग धागे में काम करने के लिए डिज़ाइन नहीं किया गया है की तरह
Invoke(new Action(() => richTextBoxReceivedMsg.AppendText(szData)));
कुछ के साथ
richTextBoxReceivedMsg.AppendText(szData);
:
करो कभी गलत पर CheckForIllegalCrossThreadCalls निर्धारित करके इसे ठीक नहीं। यह सिर्फ नाटक करता है कि वास्तव में इसे ठीक करने के बजाय कोई समस्या नहीं है ... – user2141066