在delphi XE中我可以使用启动过程,但这种方法在delphi 2007中不存在.
这个示例代码在delphi xe中运行正常,使用Start
MyThread:=TMyThread.Create(True);
MyThread.FreeOnTerminate :=True;
MyThread.Property1:=900;
MyThread.Property2:=2;
MyThread.Start;
Run Code Online (Sandbox Code Playgroud)
但是在delphi 2007中,该start过程不存在,所以我使用的是在新版本的delphi中不推荐使用的简历过程.
MyThread:=TMyThread.Create(True);
MyThread.FreeOnTerminate :=True;
MyThread.Property1:=900;
MyThread.Property2:=2;
MyThread.Resume;
Run Code Online (Sandbox Code Playgroud)
所以quieon是,resume在delphi 2007中可以使用,或者我必须使用另一种方式来启动一个被挂起的线程?
提前致谢.
我正在Delphi XE2中构建一个多线程Windows服务应用程序,它使用ADO数据库组件连接到SQL Server.我CoInitialize(nil);在内部线程之前已经使用了很多次,但在这种情况下,我有一个我不确定的函数.
调用此函数TryConnect,尝试使用给定的连接字符串连接到数据库.它在连接成功时返回true或false.问题是这个函数将在主服务线程的内部和外部使用,并且它将创建自己的临时TADOConnection组件,这需要CoInitialize...
我的问题是我还需要调用CoInitialize这个函数吗?如果我这样做,并且由于服务的执行程序CoInitialize也使用,如果我从服务中调用此函数,它们会干扰吗?该TryConnect函数位于从主服务线程创建的对象内部(但最终将移动到其自己的线程).我需要知道CoInitialize()从同一个线程(和CoUninitialize)调用两次是否会干扰 - 以及如何正确处理这种情况.
这是下面的代码......
//This is the service app's execute procedure
procedure TJDRMSvr.ServiceExecute(Sender: TService);
begin
try
CoInitialize(nil);
Startup;
try
while not Terminated do begin
DoSomeWork;
ServiceThread.ProcessRequests(False);
end;
finally
Cleanup;
CoUninitialize;
end;
except
on e: exception do begin
PostLog('EXCEPTION in Execute: '+e.Message);
end;
end;
end;
//TryConnect might be called from same service thread and another thread
function TDBPool.TryConnect(const AConnStr: …Run Code Online (Sandbox Code Playgroud)