You should read about the concept of prior art in Wikipedia. In essence, it would work, but let me highlight this:
[Prior art] constitutes all information that has been made available to the public in any form before a given date that might be relevant to a patent's claims of originality. If an invention has been described in the prior art, a patent on that invention is not valid.
So, you can avoid patents over your work if those patents are registerefregistered after you’ve already done something about it. However, it must be something public. Later on you can read:
Prior art must be available in some way to the public, and in many countries, the information needs to be recorded in a fixed form somehow.