Ignore:
Timestamp:
Jan 31, 2011, 2:16:21 PM (14 years ago)
Author:
george
Message:
  • Added: Running microthread list window.
  • Modified: Main thread is executed by application queued async call.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • MicroThreading/Demo/UMainForm.pas

    r158 r159  
    77uses
    88  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
    9   ComCtrls, ExtCtrls, Spin, UMicroThreading, DateUtils, UPlatform;
     9  ComCtrls, ExtCtrls, Spin, UMicroThreading, DateUtils, UPlatform,
     10  UMicroThreadList;
    1011
    1112type
    12 
    1313  TMainForm = class;
    1414
     
    2828    Button2: TButton;
    2929    Button3: TButton;
     30    Button4: TButton;
    3031    ButtonAddWorkers: TButton;
    3132    ButtonClearMicroThreads: TButton;
     
    4041    GroupBox2: TGroupBox;
    4142    GroupBox3: TGroupBox;
    42     Label1: TLabel;
    4343    Label10: TLabel;
    4444    Label11: TLabel;
     
    5757    Label8: TLabel;
    5858    Label9: TLabel;
    59     ListView1: TListView;
    6059    ListView2: TListView;
    6160    Memo1: TMemo;
     
    7271    procedure Button1Click(Sender: TObject);
    7372    procedure Button3Click(Sender: TObject);
     73    procedure Button4Click(Sender: TObject);
    7474    procedure ButtonSchedulerStartStopClick(Sender: TObject);
    7575    procedure Button2Click(Sender: TObject);
     
    8585    procedure FormDestroy(Sender: TObject);
    8686    procedure FormShow(Sender: TObject);
    87     procedure ListView1Data(Sender: TObject; Item: TListItem);
    8887    procedure ListView2Data(Sender: TObject; Item: TListItem);
    8988    procedure SpinEdit2Change(Sender: TObject);
     
    9291    procedure TimerRedrawTimer(Sender: TObject);
    9392  private
     93    MicroThreadList: TMicroThreadList;
    9494    procedure WorkerSubRoutine;
    9595  public
     
    117117begin
    118118  DoubleBuffered := True;
    119   ListView1.DoubleBuffered := True;
     119//  ListView1.DoubleBuffered := True;
    120120  Label6.Caption := IntToStr(GetLogicalProcessorCount);
    121121  Event := TMicroThreadEvent.Create;
     122  MicroThreadList := TMicroThreadList.Create(Self);
    122123end;
    123124
     
    144145begin
    145146  Event.SetEvent;
     147end;
     148
     149procedure TMainForm.Button4Click(Sender: TObject);
     150begin
     151  MicroThreadList.Form.Show;
    146152end;
    147153
     
    268274procedure TMainForm.FormDestroy(Sender: TObject);
    269275begin
     276  MicroThreadList.Free;
    270277  MainScheduler.Active := False;
    271278  Event.Free;
     
    279286  ButtonSchedulerStartStop.Click;
    280287  Label16.Caption := IntToStr(MainThreadID);
    281 end;
    282 
    283 procedure TMainForm.ListView1Data(Sender: TObject; Item: TListItem);
    284 begin
    285   try
    286     MainScheduler.MicroThreadsLock.Acquire;
    287     if Item.Index < MainScheduler.MicroThreads.Count then
    288     with TMicroThread(MainScheduler.MicroThreads[Item.Index]) do begin
    289       Item.Caption := IntToStr(Id);
    290       Item.SubItems.Add('');
    291       Item.SubItems.Add(IntToStr(Priority));
    292       Item.SubItems.Add(MicroThreadStateText[State]);
    293       Item.SubItems.Add(MicroThreadBlockStateText[BlockState]);
    294       Item.SubItems.Add(FloatToStr(ExecutionTime));
    295       Item.SubItems.Add(IntToStr(ExecutionCount));
    296       Item.SubItems.Add(IntToStr(Trunc(Completion * 100)) + '%');
    297       Item.SubItems.Add(IntToStr(StackUsed));
    298       Item.SubItems.Add(Name);
    299     end;
    300   finally
    301     MainScheduler.MicroThreadsLock.Release;
    302   end;
    303288end;
    304289
     
    334319procedure TMainForm.TimerRedrawTimer(Sender: TObject);
    335320begin
    336   if ListView1.Items.Count <> MainScheduler.MicroThreadCount then
    337     ListView1.Items.Count := MainScheduler.MicroThreadCount;
    338   ListView1.Items[-1];
    339   ListView1.Refresh;
    340 
    341321  if ListView2.Items.Count <> MainScheduler.ThreadPoolCount then
    342322    ListView2.Items.Count := MainScheduler.ThreadPoolCount;
Note: See TracChangeset for help on using the changeset viewer.