Sean,
I was wondering if you were able to do this. I am using the c# desktop and I am using m_CtiObject.SetAgentState(AgentState.eWorkReady, -1). However when I do this from the NotReady button click I get an exception. "Cross-thread operation not valid: Control 'SoftPhoneForm' accessed from a thread other than the thread it was created on."
I also get an IPCC Error[10110] You may not go to a wrap up state because your call has ended.
I am using the same code that is found in the btnWorkReady_Click event. After which I would like to set the status back to NotReady.
Thanks,
Rick
You are getting the CrossThreading exception because you are calling methods from a different thread than the UI Thread. WinForms apps only have one UI thread and async events such as the CILs come in on different threads. There are 2 ways to handle this.
At the top of your form ( like in the ctor ) you can set CheckForIllegalCrossThreadCalls = false; Or you can set do a context switch to the UI thread like below. This is a constant issue with WinForms apps and well documented.
Below is an excerpt from msdn but you can find a bunch of generic ways to do these calls.
http://msdn.microsoft.com/en-us/library/ms171728.aspx
<pre>
// This method demonstrates a pattern for making thread-safe // calls on a Windows Forms control. // // If the calling thread is different from the thread that // created the TextBox control, this method creates a // SetTextCallback and calls itself asynchronously using the // Invoke method. // // If the calling thread is the same as the thread that created // the TextBox control, the Text property is set directly. private void SetText(
string text)
{
// InvokeRequired required compares the thread ID of the // calling thread to the thread ID of the creating thread. // If these threads are different, it returns true. if (
this.textBox1.InvokeRequired)
{
SetTextCallback d =
new SetTextCallback(SetText);
this.Invoke(d,
new object[] { text });
}
else {
this.textBox1.Text = text;
}
}
</pre>