zoukankan      html  css  js  c++  java
  • 验证Event的全局性

    思路很简单, 创建一事件,再创建一线程等待事件,再用OpenEvent根据事件名称打开,

    MSDN说明:

    Fast user switching is implemented using Terminal Services sessions. The first user to log on uses session 0, the next user to log on uses session 1, and so on. Kernel object names must follow the guidelines outlined for Terminal Services so that applications can support multiple users.

    看得出事件具有传递性

    代码
    unit Unit1;

    interface

    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;

    type
      TestThread 
    = class(TThread)
      
    private
        I: Integer;
        
    procedure ShowMsg;
      
    protected
        
    procedure Execute; override;
      
    public
      
    end;

      TForm1 
    = class(TForm)
        Button1: TButton;
        Memo1: TMemo;
        Button2: TButton;
        Button3: TButton;
        Button4: TButton;
        Button5: TButton;
        Button6: TButton;
        Button7: TButton;
        
    procedure Button1Click(Sender: TObject);
        
    procedure Button2Click(Sender: TObject);
        
    procedure Button3Click(Sender: TObject);
        
    procedure Button4Click(Sender: TObject);
        
    procedure Button5Click(Sender: TObject);
        
    procedure Button6Click(Sender: TObject);
        
    procedure Button7Click(Sender: TObject);
      
    private
        
    { Private declarations }
      
    public
        
    { Public declarations }
      
    end;

    var
      Form1: TForm1;
      GHandle, GHandle1: THandle;

    const
      Str: 
    string = '123';

    implementation

    {$R *.dfm}

    procedure TForm1.Button1Click(Sender: TObject);
    begin
      GHandle :
    = CreateEvent(nil, True, False, PChar(Str));
      Memo1.Lines.Add(IntToStr(GHandle));
    end;

    procedure TForm1.Button2Click(Sender: TObject);
    begin
      
    try
        GHandle1 :
    = OpenEvent(EVENT_ALL_ACCESS, False, PChar(Str));
      
    finally
        Memo1.Lines.Add(SysErrorMessage(GetLastError));
      
    end;
      Memo1.Lines.Add(IntToStr(GHandle1));
    end;

    { TestThread }

    procedure TestThread.Execute;
    begin
      
    inherited;
      I :
    = 0;
      Self.FreeOnTerminate :
    = False;
      
    while not self.Terminated do
      
    begin
        WaitForSingleObject(GHandle, INFINITE);
        Synchronize(ShowMsg);
        InterlockedIncrement(I);
      
    end;
    end;

    procedure TestThread.ShowMsg;
    begin
      Form1.Memo1.Lines.Add(IntToStr(I));
    end;

    procedure TForm1.Button3Click(Sender: TObject);
    var
      T: TestThread;
    begin
      T :
    = TestThread.Create(False);
    end;

    procedure TForm1.Button4Click(Sender: TObject);
    begin
      SetEvent(GHandle);
    end;

    procedure TForm1.Button5Click(Sender: TObject);
    begin
      ResetEvent(GHandle);
    end;

    procedure TForm1.Button6Click(Sender: TObject);
    begin
      SetEvent(GHandle1);
    end;

    procedure TForm1.Button7Click(Sender: TObject);
    begin
      ResetEvent(GHandle1)
    end;

    end.
  • 相关阅读:
    android HashMap的几种遍历方法
    Android android:windowSoftInputMode属性详解
    Linux环境变量的设置和查看方法
    linux 定时执行shell脚本
    Linux 定时执行shell脚本_crontab
    Linux下修改字符集,转自
    解决Linux下Oracle中文乱码的一些心得体会 ,转自
    SSH Secure Shell Client连接Linux 命令行显示中文乱码问题 和oracle 查询数据中文乱码问题
    VMware 虚拟机(linux)增加根目录磁盘空间 转自
    linux 虚机增加硬盘大小 转自
  • 原文地址:https://www.cnblogs.com/chengxin1982/p/1752515.html
Copyright © 2011-2022 走看看