Z
zhfhe
Unregistered / Unconfirmed
GUEST, unregistred user!
刚刚按李维书上做了一个ApartmentCOM,提供test方法,该方法调用sleep(10000),奇怪的是如果两个Client端同时调用test方法,则要20秒以后第二个Client端才得到返回,这是为什么?
//Server-------------
uses ComServ;
procedure Ttest.test;
begin
Sleep(10000);
end;
initialization
TAutoObjectFactory.Create(ComServer, Ttest, Class_test,
ciMultiInstance, tmApartment);
end.
//Client-------------
var
Form1: TForm1;
myt:Itest;
FStream:IStream;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
begin
CoInitializeEx(Nil,COINIT_APARTMENTTHREADED);
//换成COINIT_MULTITHREADED或CoInitialize(nil)结果也是一样
myt:=Cotest.Create;
//加不加下面Marshal结果都一样!
CoMarshalInterThreadInterfaceInStream(IID_Itest , myt ,FStream);
myt.test;
end;
//Server-------------
uses ComServ;
procedure Ttest.test;
begin
Sleep(10000);
end;
initialization
TAutoObjectFactory.Create(ComServer, Ttest, Class_test,
ciMultiInstance, tmApartment);
end.
//Client-------------
var
Form1: TForm1;
myt:Itest;
FStream:IStream;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
begin
CoInitializeEx(Nil,COINIT_APARTMENTTHREADED);
//换成COINIT_MULTITHREADED或CoInitialize(nil)结果也是一样
myt:=Cotest.Create;
//加不加下面Marshal结果都一样!
CoMarshalInterThreadInterfaceInStream(IID_Itest , myt ,FStream);
myt.test;
end;