Re: form object
- From: James <James@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 6 Jun 2006 11:12:08 -0700
Marc,
You said I shouldn't use sleep, but I couldn't figure out how to do it with
a time in my class library.
This is what I have done:
using System.Windows.Forms;
using System.Threading;
public void fade(Form currentForm)
{
for(double i=1.0; i> 0; i-=.1)
{
currentForm.Opacity = i;
Thread.Sleep(100);
}
}
Is this dangerous? It is working for me.
James
-------------------------------------------------------------------------------------
"James" wrote:
Marc,.
Is Frank your alias???
Well, early on I thought about using a timer since a counter does not run
at the same speed on every cpu. I really don't care about burning up cpu
cycles on the local machine as they don't cost anything. I am somewhat
concerned about the differing speeds on the various local workstations.
But my first and foremost concern was to get the stupid thing to work and
since I didn't know how to reference the form and Bob and Nicholas told me
how, now I can refine the rest of the process. Now I just need to figure out
how to reference the timer.
Since I am new to C# (as Nicholas summized) solutions rather than
critiques are helpful. I already knew that I should use the timer, but I
still don't know how to.
James
"Marc Gravell" wrote:
Two observations:
1: any static method should probably be thread-aware; when dealing with
forms, this means that it should probably test currentForm.InvokeRequired
and (if true) push the method onto the owning UI's thread; I'm pretty sure
(not 100%) that Opacity has thread affinity..
2: while(z<10000) {z++;}
I don't mean to be rude - just frank; this is quite possibly the worst way
of putting a delay into code:
* It will run at different speeds on different computers
* it might even get completely removed by an optimizing compiler (typically
only in release mode)
You don't want to Sleep(), as this will hang the UI thread (unless you spin
up a second thread that alternates between Sleep() [on its own thread] and
BeginInvoke() [on the form]); a timer would be the normal implementation?
Marc
- Follow-Ups:
- Re: form object
- From: Marc Gravell
- Re: form object
- References:
- Re: form object
- From: Marc Gravell
- Re: form object
- Prev by Date: Re: Show() vs ShowDialog() Disposal Problem
- Next by Date: Re: Show() vs ShowDialog() Disposal Problem
- Previous by thread: Re: form object
- Next by thread: Re: form object
- Index(es):
Relevant Pages
|
Loading