Skip to content

Commit

Permalink
fixed filewatcher exiting after 10 seconds
Browse files Browse the repository at this point in the history
  • Loading branch information
erfg12 committed Jul 27, 2024
1 parent bfac247 commit 220ae6e
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 19 deletions.
5 changes: 3 additions & 2 deletions aol_4/Classes/chat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public static void debugOutputCallback(object source, IrcDebugMessageEventArgs a

public static void userListCallback(object source, IrcUserListReceivedEventArgs args)
{
if (args.UsersPerChannel.Count == 0)
if (args.UsersPerChannel.Count <= 0)
return;

Debug.WriteLine("Generating user list...");
Expand All @@ -178,7 +178,8 @@ public static void userListCallback(object source, IrcUserListReceivedEventArgs
if (!users.ContainsKey(channel)) // sometimes skipped?!
{
Debug.WriteLine("Creating users key " + channel);
users.TryAdd(channel, args.UsersPerChannel[usersPerChannel.Key]);
if (args.UsersPerChannel.ContainsKey(usersPerChannel.Key))
users.TryAdd(channel, args.UsersPerChannel[usersPerChannel.Key]);
continue;
}
// check if offline user is still in list
Expand Down
8 changes: 4 additions & 4 deletions aol_4/Classes/email.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ public static bool checkNewEmail()
Debug.WriteLine("[MAIL] YOU'VE GOT NEW MAIL!!");
return true;
}
else
{
Debug.WriteLine("[MAIL] nothing new");
}
//else
//{
// Debug.WriteLine("[MAIL] nothing new");
//}

client.Disconnect(true);

Expand Down
9 changes: 5 additions & 4 deletions aol_4/Forms/chatroom.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 20 additions & 9 deletions aol_4/Forms/chatroom.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public partial class chatroom : Win95Theme
string roomname = "";
string pChat = "";
int pplCount = 0;
FileSystemWatcher watch = null;
List<Rectangle> rects = new List<Rectangle>();
bool formClosing = false;

Expand Down Expand Up @@ -53,6 +54,8 @@ public chatroom(string channel)
}
chat.irc.SendRawMessage("join #" + channel);

keepReading();

InitializeComponent();
}

Expand All @@ -62,12 +65,15 @@ private void chatroom_Shown(object sender, EventArgs e)
//chat.users.Clear();
Text = pChat + " Chatroom";
mainTitle.Text = pChat + " Chatroom";

writeFileToBox(true);

if (!backgroundWorker1.IsBusy)
backgroundWorker1.RunWorkerAsync();

rects.Add(new Rectangle(423, 467, 54, 23)); // 0 send button
rects.Add(new Rectangle(532, 265, 39, 50)); // 1 buddy info
rects.Add(new Rectangle(574, 265, 39, 50)); // 2 ignore user
//rects.Add(new Rectangle(423, 467, 54, 23)); // 0 send button
//rects.Add(new Rectangle(532, 265, 39, 50)); // 1 buddy info
//rects.Add(new Rectangle(574, 265, 39, 50)); // 2 ignore user
}

private void writeFileToBox(bool init = false)
Expand Down Expand Up @@ -96,30 +102,35 @@ private void writeFileToBox(bool init = false)
chatRoomTextBox.AppendText(lastLine + Environment.NewLine);
chatRoomTextBox.ScrollToCaret();
}));
} else
{
Debug.WriteLine("[ERROR] handle creation failed?");
}
//} catch { Debug.WriteLine("writeFileToBox just crashed."); }
}

public void OnChanged(object source, FileSystemEventArgs e)
{
writeFileToBox();
if (e.ChangeType == WatcherChangeTypes.Changed)
{
Debug.WriteLine($"Changed: {e.FullPath}");
writeFileToBox();
}
}

public void keepReading()
private void keepReading()
{
var watch = new FileSystemWatcher();
watch = new FileSystemWatcher();
watch.Path = Path.GetDirectoryName(chatlog);
watch.Filter = Path.GetFileName(chatlog);
watch.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite;
watch.Changed += new FileSystemEventHandler(OnChanged);
watch.EnableRaisingEvents = true;
Debug.WriteLine($"watching {chatlog} for changes");
}

private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
writeFileToBox(true);
keepReading();

// keep users list up to date
while (true)
{
Expand Down

0 comments on commit 220ae6e

Please sign in to comment.