Dec 2, 2013 08:18 AM
(This post was last modified: Dec 2, 2013 08:18 AM by Washi.)
There are some issues with this code. Try for example adding a progress bar with a marquee style on this form, and you'll notice what's wrong.
The progress bar just animates way faster than it should. After it has finished moving the form up, you'll see it freezes for a second and fades out. This means you have clearly not used threading well, as you are still blocking the UI thread with this Invoke call, and keep refreshing the form for too many times, which gives unwanted results, just to get its position right.
Actually, why using a thread anyway? Timers don't cause thread problems and are well-suited for these operations. I don't see why people forget about these things.
(Dec 2, 2013 08:18 AM)Washi Wrote: There are some issues with this code. Try for example adding a progress bar with a marquee style on this form, and you'll notice what's wrong.
The progress bar just animates way faster than it should. After it has finished moving the form up, you'll see it freezes for a second and fades out. This means you have clearly not used threading well, as you are still blocking the UI thread with this Invoke call, and keep refreshing the form for too many times, which gives unwanted results, just to get its position right.
Actually, why using a thread anyway? Timers don't cause thread problems and are well-suited for these operations. I don't see why people forget about these things.
This could have been done better but you have to understand that I am not a skilled coder as you are. I did it my way and for my needs it does the job. Anyway thanks for the feedback, I appreciate it.
"Never be a spectator of unfairness or stupidity. Seek out argument and disputation for their own sake; the grave will supply plenty of time for silence." - C.H.
You should seriously be using timers instead of threads in this situation. Like, do you even understand what to use in a given scenario?
Thank you for sharing this!
:.:.:::.:.:::.:.:::.:.:::.:.::
(Dec 2, 2013 09:38 AM)tweety Wrote: You should seriously be using timers instead of threads in this situation. Like, do you even understand what to use in a given scenario?
I already made a version with timers. I will update thread soon.
"Never be a spectator of unfairness or stupidity. Seek out argument and disputation for their own sake; the grave will supply plenty of time for silence." - C.H.
DO NOT DEAL WITH THIS MEMBER
Well, I have something like this but done in another way kinda... Nice share tough.
(Dec 2, 2013 09:38 AM)tweety Wrote: You should seriously be using timers instead of threads in this situation. Like, do you even understand what to use in a given scenario?
OK, now I'm literally in o_O position. Why ? Because if he originally used a timer, everyone would call him a skiddo and a shitface. But now when he used a thread, everyone that is "ub3r l33t" is just arguing. Soo, don't just say, use timers, but give a better solution.
Dec 2, 2013 01:30 PM
(This post was last modified: Dec 2, 2013 01:44 PM by Nervo.)
(Dec 2, 2013 01:23 PM)SIM-1456245 Wrote: OK, now I'm literally in o_O position. Why ? Because if he originally used a timer, everyone would call him a skiddo and a shitface. But now when he used a thread, everyone that is "ub3r l33t" is just arguing. Soo, don't just say, use timers, but give a better solution.
This is exactly what I thought at the first place. Timers are actually a nice way of doing this, but if I used them, I would be probably called a skid.
"Never be a spectator of unfairness or stupidity. Seek out argument and disputation for their own sake; the grave will supply plenty of time for silence." - C.H.
(Dec 2, 2013 01:23 PM)SIM-1456245 Wrote: OK, now I'm literally in o_O position. Why ? Because if he originally used a timer, everyone would call him a skiddo and a shitface. But now when he used a thread, everyone that is "ub3r l33t" is just arguing. Soo, don't just say, use timers, but give a better solution.
What do you mean, "a better solution"?
Timers are used to carry out operations periodically, so that's the way to go here.
Dec 2, 2013 02:23 PM
(This post was last modified: Dec 2, 2013 02:31 PM by Washi.)
(Dec 2, 2013 01:30 PM)Nervo Wrote: This is exactly what I thought at the first place. Timers are actually a nice way of doing this, but if I used them, I would be probably called a skid.
All those guys who are thinking this are wrong. There are some misunderstandings about threads and timers. They often get twisted for a reason I do not know of (It's like to me it sounds pretty obvious, but that might be just me =p).
From my understanding timers are meant to do a specific operation periodically using a specific interval. You can think of operations that should be done after a couple of minutes, like some kind of scheduled task, or just milliseconds, for applying fairly simple animations in an application like yours.
A thread however should be used for a single operation that has to be executed separately (and asynchronously) from others without blocking everything else. This has advantages, it provides speed and you can still control other threads such as the main thread, which is in many cases the UI thread. Of course it has disadvantages. One very well-known problem is running cross-threading operations, which are not allowed to be done. This can be solved as you know by the Invoke method.
So in short, you should use timers for operations that should take place periodically, and threads for parts of programs that need to be done asynchronously, without using delays or anything like that.
(Dec 2, 2013 02:23 PM)Washi Wrote: All those guys who are thinking this are wrong. There are some misunderstandings about threads and timers. They often get twisted for a reason I do not know of (It's like to me it sounds pretty obvious, but that might be just me =p).
From my understanding timers are meant to do a specific operation periodically using a specific interval. You can think of operations that should be done after a couple of minutes, like some kind of scheduled task, or just milliseconds, for applying fairly simple animations in an application like yours.
A thread however should be used for a single operation that has to be executed separately (and asynchronously) from others without blocking everything else. This has advantages, it provides speed and you can still control other threads such as the main thread, which is in many cases the UI thread. Of course it has disadvantages. One very well-known problem is running cross-threading operations, which are not allowed to be done. This can be solved as you know by the Invoke method.
So in short, you should use timers for operations that should take place periodically, and threads for parts of programs that need to be done asynchronously, without using delays or anything like that.
Yeah, you are right. I will try to be more careful with this kind of stuff next time. Thanks for everything 👍
"Never be a spectator of unfairness or stupidity. Seek out argument and disputation for their own sake; the grave will supply plenty of time for silence." - C.H.
(Dec 2, 2013 02:23 PM)Washi Wrote: All those guys who are thinking this are wrong. There are some misunderstandings about threads and timers. They often get twisted for a reason I do not know of (It's like to me it sounds pretty obvious, but that might be just me =p).
From my understanding timers are meant to do a specific operation periodically using a specific interval. You can think of operations that should be done after a couple of minutes, like some kind of scheduled task, or just milliseconds, for applying fairly simple animations in an application like yours.
A thread however should be used for a single operation that has to be executed separately (and asynchronously) from others without blocking everything else. This has advantages, it provides speed and you can still control other threads such as the main thread, which is in many cases the UI thread. Of course it has disadvantages. One very well-known problem is running cross-threading operations, which are not allowed to be done. This can be solved as you know by the Invoke method.
So in short, you should use timers for operations that should take place periodically, and threads for parts of programs that need to be done asynchronously, without using delays or anything like that.
Yes, someone that understands timers and intervals. Thank you for the extremely nice explanation. I'll redirect everyone that is complaining about timers to this post.
I'd say that you can use timers to do whatever you want, but you are sure that that operation won't take too long to execute, thus blocking the main thread.
Nice tutorial brother.. I will try this tutorial soon
Dec 3, 2013 12:06 PM
(This post was last modified: Dec 3, 2013 05:07 PM by SubGenius.)
I didn't want to make a new thread for this, people might say i am leeching your work, I am contributing.
I have coded an advanced version of yours, without threadings, using a timer.
What's New.- PopUp Window Template Included
- Pending List
- Fade in - Fade out Support
- Walk In - Walk out Support
- Show popup in every corner of your screen
- Visibility time can be changed.
- Source code fully commented
Documentation
How to add : - Create a visual basic project
- Add an empty class file
- Put the code inside
- Build the solution
To Create a popup from the template look at the example:
Code Sub ShowPopUp
Dim popUpManager As New AdvancedPopUpManager
Dim WindowPopUp As New AdvancedPopUpManager.PopUpWindow(New PopUpWindowTemplate("Title-Test", "Write Something", True)) With {.secondsVisible = 4, .startLocation = AdvancedPopUpManager.PopUpWindow.StartLocationEnum.UpRight, .type = AdvancedPopUpManager.PopUpWindow.PopUpTypeEnum.FadeIn_FadeOut}
popUpManager.ShowPopUp(WindowPopUp)
You can replace the template with every form of your preference.
Available Methods:
ShowPopUp ---> Shows a new popup window without adding to pending list.
AddNewPopUp ---> Adds a new popup window to the pending list
ShowNextPopUp ---> Use this to start showing the the popups in the pending list
ClearPendingPopUps ---> Deletes all panding popups
Notes
If there is a popup being showed and you add or show a new popup, the new popup is going to be showned only after the previous popup has ended.
If the user closes the popup form , the timer will continue to work and the pending list will continue to show the popups.
The Code:
http://pastebin.com/XLJuHfkj#
DO NOT DEAL WITH THIS MEMBER
Oh god :)
It's make really beautiful software for us.
Thanks for share man
|