Click here to Skip to main content
15,868,016 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hai guys,

In my project i am using 3 different timer control for move 3 different listviews items one by one... so my application shows very slow process. I can't able to click other button, After stopped the timer only other controls are work without time gap.


How can i resolve this problem? Is there any solutions?

Regards
vasanth
Posted
Comments
[no name] 10-Aug-12 14:52pm    
Sounds more like you have a bad application design.
Wendelius 10-Aug-12 14:59pm    
I agree that this sounds like bad design. Could you explain what you're trying to achieve. Why the timers are used to move items etc.
Sergey Alexandrovich Kryukov 10-Aug-12 15:13pm    
I agree, too, but I provided some general advice -- please see.
--SA
vasanthkumarmk 10-Aug-12 15:03pm    
Just i have list view control contains some 20 items, when i click the button the top most item will select and after few seconds that selection will move to next, like that it will move up to end of the list one by one.

Thats why i am using timer to selection moves.

Timers are generally bad. One timer, System.Windows.Forms.Timer is the easiest but provide unacceptable accuracy (there are rare cases when that's all right, but not like yours), other two are better, but there is a lot of bothering with them. Did you ever try to account for the situation when a new timer event is invoked when your timer event handler is still executing?

Threads is much more straightforward way, because the logic is linear. You need to create a separate thread with a loop with some delay using Thread.Sleep.

First of all, I recommend using a thread wrapper to solve the problem of passing parameters to it. Please see my past solutions:
How to pass ref parameter to the thread[^],
change paramters of thread (producer) after it started[^].

Now, you need to update your UI in each cycle. On problem is: you cannot call anything related to UI from non-UI thread. Instead, you need to use the method Invoke or BeginInvoke of System.Windows.Threading.Dispatcher (for both Forms or WPF) or System.Windows.Forms.Control (Forms only).

[EDIT]

By the way, two "normal" timers (other than System.Windows.Forms.Timer) will need UI thread invocation described above anyway, so you cannot win with a timer by not doing the invocation.

[END EDIT]

You will find detailed explanation of how it works and code samples in my past answers:
Control.Invoke() vs. Control.BeginInvoke()[^],
Problem with Treeview Scanner And MD5[^].

See also more references on threading:
How to get a keydown event to operate on a different thread in vb.net[^],
Control events not firing after enable disable + multithreading[^].

—SA
 
Share this answer
 
v2
Comments
Wendelius 10-Aug-12 15:18pm    
Good points! I still wonder why the three timers etc. One reason could be to create a small animation, but that would explain the amount of the timers...
Sergey Alexandrovich Kryukov 10-Aug-12 15:23pm    
I think can answer to this, more or less.

System.Timers.Timer is just a little wrapper around System.Threading.Timer, for convenience; and this one is the most reasonable. And System.Windows.Forms.Timer is created for the weak-minded, mostly. :-) For Microsoft, it always has been one of the most important priority to please such people. One benefit of it: the event is executed in UI thread, so no UI invocation is required (it is needed for "normal" timer anyway). The accuracy of this timer is simply amazing. I know only one use of it: a big one-time delay in UI, such as splash screen.

--SA
Wendelius 10-Aug-12 15:28pm    
That's a fair guess. And it seems that the OP clarified the situation a bit.
Sergey Alexandrovich Kryukov 10-Aug-12 15:29pm    
Hope so; thank you, Mika.
--SA
Sergey Alexandrovich Kryukov 10-Aug-12 15:28pm    
By the way, the small (or big) animation with timers is even worse, so it should use threading. The timers are still needed in some cases.
--SA
Hi
I think if u use multi thread programming , it'll work.

Good Luck
 
Share this answer
 
Comments
vasanthkumarmk 10-Aug-12 15:04pm    
But how?
Sergey Alexandrovich Kryukov 10-Aug-12 15:12pm    
How? Please see my answer. What else would you need to get explained?
-SA
S.Roshan 10-Aug-12 15:16pm    
I'm sorry, i don't know how it is possible. i'm not a professional developer, Just as my teacher told us before, sometimes, using multi threading may work.
Maciej Los 10-Aug-12 15:29pm    
Use links provided by Sergey (SA).

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900