How can I make a text file immediately appear in my project from an AssetPostProcessor script?

When I right click in the project and add a new text file (e.g. c# script) it appears immediately. Likewise, if I create a new text file in an external text editor, it appears immediately in my Unity project view.

However, if I use StreamWriter in an AssetPostProcessor script to create a text file, it does not appear in my project unless I either:

  1. reimport the new script's parent folder or
  2. add or save a text file through one of the other (previously mentioned) means

Right now I am working around this by using AssetDatabase.CreateAsset() to create a material with a .cs extension and then using StreamWriter to overwrite it, but its contents still don't refresh unless I do (1) or (2) above. Is there a better or different way to handle this?

Have you tried using AssetDatabase.ImportAsset to force an import/update after creating the file?