简体   繁体   中英

Infinite cycle (While) and enable control MS Access Form 2003

I made function which use do while(true) - infinite loop (which controls other apps)

I am searching solution how to make form accessable - when I start app, access just loading and my form cannot be changed. At least I tried to make some "listening function" for key "S" to stop while and it doesnt work too (maybe I am doing it bad, is it possible?)

I just used

Do While (run) <code> Loop

I guess I will need at least 2 thread (1 thread handle infinite while, 2 thread for form, but I read access cannot handle Multithreading.)

I can ask, is there some possibility of make this work?

Jan.

MS Access or MS office are single threaded platforms and cannot perform parallel executions. Generally, having a blind loop or uncontrolled loop is not a good practice at all. If you have a blind loop function without a controller, you are wasting process cycles of your vba application.

what you can do:

  1. use timer and set intervals how often your code must execute
  2. Add "Do events" within the loop to use the process cycles to execute some other code when a code within loop is waiting for an external signal.
  3. Add any sort of controller to break the loop.. simple if else condition
  4. Migrate your code to an external .DLL and execute/control the function outside VBA

In short, VBA cannot perform threading. Using uncontrolled will freeze your application which will force you to use [CTRL] + F12 to stop the execution manually.

我使用了函数“ DoEvents” (至少对输入有反应-键盘/鼠标)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM