-2

I am trying to make a chat program which reads text from a text file on a shared folder.

The problem I am having is when you type stuff it doesn't refresh meaning if someone else adds anything else to the text file you wont see it does anyone have an idea of how to fix this.

(this is a console program and I am new to c#)

2 Answers2

0

You will need to either constantly be reading from the text file and have some way to detect changes. Otherwise I would seriously suggest not to use a text file for this kind of application.

Ideally you would want to be able to directly make a push to the application when new data is added. It might be worth researching into Socket Programming.

Tom Bowen
  • 8,214
  • 4
  • 22
  • 42
-1

As @TomBowen suggested, text files should not be used for this purpose. However, for learning purposes, we can oversee that.

I would suggest caching the path to your shared file. Have a loop (preferably async) that would constantly check when the file is updated and save the modified date locally. Do this by checking the last time the file was modified (How do I get modified date from file in C# on Windows Mobile?). If the modification date does not match your saved one - clear the console, read all the text file's content and print it to the console.

This would be a very primitive approach with tons of possibilities for stuff to fail. But it would work just for the sake of making something.

tsvedas
  • 1,049
  • 7
  • 18