>> private void OnLineStatChg(object sender, EventArgs e) >> { >> //This event handler fires whenever the status of a clsLine (phone line) changes >> //Find the corresponding screen line representation, then call the refresh code, below. >> >> //I added the following line for debugging and it does display the text >> if (this.InvokeRequired == true) Debug.WriteLine("Invoke Required"); >> >> clsLine theline = (clsLine) sender; >> foreach (CtlPhoneLine1 obj in this.Controls) >> { >> if (obj is CtlPhoneLine1) >> { >> if (obj.Index == theline.Index) >> { >> this.RefreshLine(theline, obj); >> goto FoundIt; >> } >> } >> } >> FoundIt: >> return; >> } >>>>
>> private void RefreshLine( clsLine LineObj, CtlPhoneLine1 LineCtl) >> { >> //This code sets the properties of the appropriate ctlPhoneLine control >> //When a call enters or leaves the queue. >> LineCtl.CallerId = LineObj.Callerid; >> LineCtl.CallerIdName = LineObj.Callername; >> switch (LineObj.State) >> { >> case LineState.LineClear: >> LineCtl.Status = "Clear"; >> break; >> case LineState.LineRinging: >> LineCtl.Status = "Ringing"; >> break; >> case LineState.lineHungup: >> LineCtl.Status = "Hungup"; >> break; >> } >> } >>>>
>> public string Status >> { >> get >> { >> return this._status; >> } >> set >> { >> this._status = value; >> //Call a method to re-set control appearance based on state >> this.SetAppearance(this._status); >> } >> } >>>>
>> private void SetAppearance(string state) >> { >> switch (state) >> { >> case "Ringing": >> tmrFlash.Start(); >> lblStatus.Text = state; >> this.BackColor = Color.Red; >> break; >> case "Hungup": >> tmrFlash.Stop(); >> lblStatus.Text = "Available"; >> this.BackColor = Color.Yellow; >> break; >> case "Clear": >> tmrFlash.Stop(); >> lblStatus.Text = "Available"; >> this.BackColor = Color.Yellow; >> break; >> } >> } >>>>
private delegate void RefreshLineCallback(clsLine LineObj, CtlPhoneLine1 LineCtl); private void OnLineStatChg(object sender, EventArgs e) { //This event handler fires whenever the status of a clsLine (phone line) changes //Find the corresponding screen line representation, then call the refresh code, below. clsLine theline = (clsLine)sender; foreach (CtlPhoneLine1 obj in this.Controls) { if (obj is CtlPhoneLine1) { if (obj.Index == theline.Index) { if (this.InvokeRequired == true) { this.Invoke(new RefreshLineCallback(RefreshLine), theline, obj); } else { this.RefreshLine(theline, obj); } goto FoundIt; } } } FoundIt: return; }A good lesson learned here - one which I think every .NET Winforms developer will come across at some time or other.