home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 2005 June (DVD) / DPPRO0605DVD.iso / Install / program files / Borland / BDS / 3.0 / Demos / Delphi.Net / CLR / Threading / threadstatic.dpr < prev    next >
Encoding:
Text File  |  2004-10-22  |  1.1 KB  |  60 lines

  1. program threadstatic.dpr;
  2. {$APPTYPE CONSOLE}
  3.  
  4. //
  5. // This example demonstrates how to use native .NET methods to create a thread on 
  6. // a class with a static class method.
  7. //
  8. // Written by: Rick Ross (http://www.rick-ross.com/)
  9. //
  10.  
  11. uses
  12.    System.Threading;
  13.  
  14. type
  15.   ThreadMe = class
  16.   public
  17.     class procedure MyThreadMethod; static;
  18.   end;
  19.  
  20. class procedure ThreadMe.MyThreadMethod;
  21. var
  22.   stop : integer;
  23.   curNum : integer;
  24.   rnd    : System.Random;
  25.  
  26. begin
  27.   rnd    := System.Random.Create;
  28.   curNum := rnd.Next(1000);
  29.   stop := curNum + 10;
  30.   while curNum < stop do
  31.   begin
  32.     writeln('Thread ', System.Threading.Thread.CurrentThread.Name ,
  33.             ' current value is ',curNum);
  34.     inc(curNum);
  35.     Thread.Sleep( 3 );
  36.   end; 
  37. end;
  38.  
  39. var
  40.   thrd1 : Thread;
  41.   thrd2 : Thread;
  42.  
  43. begin
  44.   writeln('Staring threading instance example...');
  45.  
  46.   thrd1 := Thread.Create( @ThreadMe.MyThreadMethod );
  47.   thrd1.Name := 'one';
  48.  
  49.   thrd2 := Thread.create( @ThreadMe.MyThreadMethod );
  50.   thrd2.Name := 'two';
  51.  
  52.   thrd1.Start();
  53.   thrd2.Start();
  54.  
  55.   readln;
  56.  
  57.   writeln('Done');
  58. end.
  59.  
  60.