Re: form object



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



.



Relevant Pages

  • Re: question about thread scheduling
    ... I will try what you suggested, the reason that I didn't use the sleep method ... whatsoever to tamper with the timer tick. ... If the NN run in a different thread as the control loop ...
    (microsoft.public.windowsce.platbuilder)
  • Re: Putting the screen (and only the screen) to sleep
    ... go down the "pmset" path, but defaults and AppleScript I believe ... if timer is "Sleep is on original time" then ... set displaysleep to do shell script "pmset force -a ...
    (comp.sys.mac.system)
  • Re: Windows Service and Threading
    ... all you have to do is stop the timer. ... a windows service which starts up three threads which run in a while loop ... These threads each sleep for X ... basically running in an infinite loop. ...
    (microsoft.public.dotnet.framework.windowsforms)
  • Re: What is the equivalent in O2K vb to "Sleep()"?
    ... Is there a possible workaround that somehow does what sleep _should_ do, ... Private Sub Application_Startup ... An alternative would be if you have a 3rd party timer control available ... ' This line is so that you can use "Sleep" in any macro. ...
    (microsoft.public.outlook.program_vba)
  • Re: PROBLEM: high load average when idle
    ... High load average is due to either a task chewing a ... lot of CPU time or a task stuck in uninterruptible sleep. ... to change by the time we actually add the timer, so the goal of trying to ...
    (Linux-Kernel)

Loading