![]() |
#2
詹斯邦2025-10-02 17:25
So, without going into details of why to do things this way, just the instructions of what to create and how to use it.
1. Build a COM Server "background.process" 1a) Create a new folder "background" 1b) Open VFP this way: 图示为以管理员身份证运行Vfp9 1c) Create a project in the background folder you call "background.pjx" - that way a build of the project will create a background.EXE 1d) Create this as the main.prg of the background.pjx project CODE #Define CRLF Chr(13)+Chr(10) Define Class Process As Form OlePublic Hidden ExecuteScriptMessage Script = '' ExecuteScriptMessage = 0 Executing = .F. ErrorHappened = .F. LastReturnValue = .null. LastError = '' Procedure Init() On Shutdown Quit * modal states are unwanted, which we can enfore: Sys(2335,0) && enable unattended server mode Declare Integer RegisterWindowMessage In User32.Dll String cMessage Declare Integer PostMessage In User32.Dll Integer nHWnd, Integer nMsg, Integer wParams, Integer lParams This.ExecuteScriptMessage = RegisterWindowMessage('BackgroundProcess_ExecuteQueuedTasks') If Between(This.ExecuteScriptMessage, 0xC000, 0xFFFF) Bindevent(Thisform.HWnd, This.ExecuteScriptMessage , This, 'ExecuteScript', 2+4) Else Quit EndIf Endproc Procedure Execute() ; HelpString "Execute code in Script property" Local llDone If Not This.Executing && do nothing, if a script still runs This.Executing = .T. This.ErrorHappened = .F. * Postmessage causes ExecuteScript to run, because of the BindEvent in the Init(). PostMessage(Thisform.HWnd, This.ExecuteScriptMessage, 0, 0) llDone = .T. EndIf Return llDone Endproc Hidden Procedure ExecuteScript(HWnd As Integer, Msg As Integer, wParam As Integer, Lparam As Integer) This.LastReturnValue = Execscript(This.Script) This.Executing = .F. Return 0 Endproc Procedure Error(nError, cMethod, nLine) This.Executing = .F. This.ErrorHappened = .T. This.LastError = Textmerge("Error <<nError>> in <<cMethod>> Line <<nLine>>: <<Message()>>",.T.) Endproc Procedure Quit() ; HelpString "end the background process" Do While Sys(3098,This)>0 DoEvents Enddo Endproc Procedure Destroy() Sys(2335,1) && disable unattended server mode again On Shutdown Quit Endproc Enddefine 1e) build the EXE Now you will have a background.process COM server in your system. 2. Using the Background.Process COM server. This new COM server has the following properties and methods of interest: |
由于正在看文章,所以一些可见的中文化没有完全做,姑且有能力的坛友,自己看哈
So this is for anybody interested in parallel code execution.
And I know I could point out several things already existing, I even did in posts in these threads. I mentioned the existence of ParallelFox: https://
I mentioned the simplest parallel execution possible with RUN /N another.EXE, possibly with parameters.
I mentioned you could run two executables and do IPC - interprocess communication - with windows messages.
我提到过,您可以运行两个可执行文件,并使用windows消息进行IPC(进程间通信)。
I mentioned an approach of Calvin Hsia to allow multithreading and pointed out it has the problem of being data execution, which Windows prevents with data execution prevention - in short DEP.
我提到了Calvin Hsia的一种允许多线程的方法,并指出它存在数据执行的问题,Windows通过数据执行保护——简称DEP——来防止这一点。
And there's more about parallel processing or multithreading with FoxPro out in the internet already, so actually no need to come up with anything new, but I wanted to point out one thing that I think all existing solutions overlooked so far. Making use of an out-of-process COM server as a background process. I'll go into the technical details in one or a few separate posts, this is just the instructions and usage post:
关于FoxPro的并行处理或多线程技术,网上已有大量相关资料,其实无需再赘述。不过我想强调一个现有方案至今都忽略的关键点:
将跨进程COM服务器作为后台进程运行。
具体技术细节我会在后续一两篇独立文章中详细讲解,本文仅提供操作指南和使用说明: