# uwaitfor command

The uwaitfor command causes the process to wait until the Windows
 application, identified by the *var* variable, terminates or the time specified
 by the *expr* variable elapses.

## Format

```

 UWAITFOR var, expr THEN statement(s) ELSE statement(s)
```

## Parameters

| var | Must be an identifier returned by the uexecute command. |
| --- | --- |
| expr | Indicates time, in 1/100th seconds. |
| THEN/ELSE statements | If the uwaitfor command time expires, the ELSE clause is executed. If the application terminates, the THEN clause is executed. |

## Example(s)

**Example 1**

```
 *
 * Launch Notepad; Allow user 3 seconds to
 * Complete edit. If not done in 3 seconds
 * Close application for them.
 *
 UEXECUTE "NOTEPAD.EXE" RETURNING HANDLE
 UWAITFOR HANDLE, 300 ELSE
 UMESSAGE TO HANDLE,16,0,""
 END
```

 **Example 2**

 Running the following program will close Notepad.exe after 5 seconds:

```
 001 UEXECUTE "NOTEPAD.EXE" RETURNING HANDLE
 002
 003 UWAITFOR HANDLE, 500 THEN
 004 __PRINT "THANKS FOR WAITING"
 005 END ELSE
 006 __UMESSAGE TO HANDLE,16,0,""
 007 END
```

## See also

- [O/S interoperability commands and functions](https://d3codex.com/pickbasic-flashbasic/os-interoperability-commands/)
- [uclose command](https://d3codex.com/pickbasic-flashbasic/uclose-command/)
- [ucreate command](https://d3codex.com/pickbasic-flashbasic/ucreate-command/)
- [udelete command](https://d3codex.com/pickbasic-flashbasic/udelete-command/)
- [uerror() function](https://d3codex.com/pickbasic-flashbasic/uerror-function/)
- [uexecute command](https://d3codex.com/pickbasic-flashbasic/uexecute-command/)
- [ulock command](https://d3codex.com/pickbasic-flashbasic/ulock-command/)
- [ulseek() function](https://d3codex.com/pickbasic-flashbasic/ulseek-function/)
- [umessage command](https://d3codex.com/pickbasic-flashbasic/umessage-command/)
- [uopen command](https://d3codex.com/pickbasic-flashbasic/uopen-command/)
- [uread command](https://d3codex.com/pickbasic-flashbasic/uread-command/)
- [ureadline() function](https://d3codex.com/pickbasic-flashbasic/ureadline-function/)
- [usystem() function](https://d3codex.com/pickbasic-flashbasic/usystem-function/)
- [uwrite command](https://d3codex.com/pickbasic-flashbasic/uwrite-command/)

---
Source: https://d3codex.com/pickbasic-flashbasic/uwaitfor-command/ - part of the D3Codex reference.
