>Hi Mark,
>
>>Hi,
>>
>>I'm a VFP guy, just getting a handle on C#.
>>
>>I have a Winform, containing some custom controls (assemblies of buttons, labels and text boxes).
>>
>>I have an event being created (when a telephone call is received) and at that time I change some text on one of the custom controls.
>>
>>So far, so good - all works well.
>>
>>Now, when the phone rings, I want the line status text on my custom control to flash 'Ringing' rather than just display the word. So, I have added a timer that runs every second (when enabled) and changes the ForeColor of the status label to give a flashing effect.
>>
>>Except - it doesn't flash.
>>
>>I think it has something to do with threads. The fact that the timer on the custom control is enabled from an event handler seems to inhibit it's function somehow.
>>
>>If I set the timer to enabled at design time, then the text flashes from the start, proving that my flash code is OK.
>>
>>Any suggestions greatfully received.
>
>If you are using VS2005 or VS2008 you should get a cross thread exception if that was the case and I understand you correctly. Try using Invoke on your method like this.
>
>/// <summary>
>/// MyOtherThread Event Handler
>/// </summary>
>private void myOtherThread_EventFired(object o, SomeEventArgs e)
>{ this.Invoke(new SomeDelegate(OnMyEvent), new object[] { o, e }); }
>private void OnMyEvent(object sender, SomeEventArgs e)
>{
> // Change your control properties here
>}
>
>
>Otherwise, maybe you could post some of your code showing how you are trying to enable the timer and the timer method that is changing your text value. We could probably get a better idea of what is happening. Also if the label you are trying to change is inside a user control then you will have to handle it a bit differently. Try posting some code.
>Tim
Hi Tim,
It's VS 2008. You are correct about the cross thread exception. I did encounter this when I wrote the code to change the status text on my control via the event handler. I cheated and added
Control.CheckForIllegalCrossThreadCalls = false;
to the start of my form.
Looks like I'm going to have to bite the bullet and do it the right way. I had just worked out the whole event/delegate bit when I first wrote this code so I had a headache at the time.
The label (and other stuff) that needs to be changed IS inside a custom control (which is added to the form dynamically at run-time) - how much different does this make it from your proposed solution above?
Thanks.