I need to know if use of ProcessMessages that allow me to use entire application is legal.

Pseudo code:

Main thread button call - search.

```
procedure ButtonOnClick;
begin
    var1 = ExecuteSearch();
end;    

function ExecuteSearch:Something;
begin
 thread.StartThread;
 while thread.Finished do
 Application.ProcessMessages;
 result := something;
end;

```

When I use this construction I can click other parts of my software and use it. But I don't know how this works. And if its safe.