المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Starting intrupped thread again..



C# Programming
06-26-2011, 10:25 AM
Hi,

I need to design a program should be able to update certain textbox for each event inside the GUI and after every 10 seconds of most recent event, text tox should be back to original value..Let say

Event one occurs --> text box updated --> after 10 seconds --> text box back to normal

This is the case in perfect world, but it might be possible that someone create another GUI event during this period of 10 seconds..

Event one occurs --> text box updated --> after 8 seconds --> event two occurs --> GUI updated --> after 2 seconds the other thread (10 seconds completed for first event), text box back to normal.

So in this case, for second event, the textbox get back to original value in just 2 seconds. I know I could use thread intrupt to cancel the other thread. But my question is, it the best way of doing it?? And what is there any other way to starting intrupped thread again, without making a new thread? Will thread intrupt make sure everything will go perfect?? Would you suggest some more efficient way? I may be misunderstanding about threading here, please forgive that. Any suggestions, links or comments will be appreciated.

PS
So far my code is like this..

Thread t = new Thread(keep_run); public void update() { t.Interrupt(); if (MessageLbl.InvokeRequired) { MessageLbl.Invoke(new setText(() => MessageLbl.Text = "User settings have been updated.")); } else { MessageLbl.Text = "User settings have been updated."; } t = new Thread(keep_run); t.Start(); } private void keep_run() { try { Thread.Sleep(10000); MessageLbl.Invoke(new setText(() => MessageLbl.Text = "Welcome to MAT Downloader")); } catch { MessageBox.Show("Interrupted"); } } }
If you find any other problems with the code then do mention them.

Thanks
Regards,
Shivam Kalra http://www.barakasoft.com/script/Forums/Images/smiley_smile.gif