Share via

C# WinForms, static, Logger, Thread problems

Markus Freitag 3,791 Reputation points
2021-07-30T19:33:47.343+00:00

Hello,

I call this function Logger.Write("TEST"); from a WinForm application several times!
When I close the WinForm, it does not exit correctly.
It hangs. Thread I close all. (see the code)
Does anyone see the cause? Can anyone tell me the solution?
Thanks for your help in advance!

Something has to be open or is it static?

////////////////////////////////////////////////////////////////  
  
private void btnInit_Click(object sender, EventArgs e)  
{  
   string retInit=  MyApp.Init("C:\\MyApp\\", "C:\\MyApp\\MyAppManual.XML", "C:\\MyApp\\Log\\");  
   txtResponse.Text += retInit + Environment.NewLine;  
}  
  
private void frmMain_FormClosed(object sender, FormClosedEventArgs e)  
{  
 MyApp.Close();  
}  
  
public static string Init(string rootPath, string configfile, string logFolder)  
{  
 try  
 {  
 string currentPath = Directory.GetCurrentDirectory();  
  
 string logPath = currentPath + "\\Log\\";  
 var dirLog = Directory.CreateDirectory("C:\\MyApp\\LogMES\\");  
 Logger.LogDirPath = "C:\\MyApp\\Log"; // XX  
 Logger.Write("TEST");  
  
public static void Close()  
{  
    Logger.Close();  
}  

See logging code in the attachment.

119512-logging.txt

Developer technologies | C#
Developer technologies | C#

An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.

0 comments No comments

Answer accepted by question author

Karen Payne MVP 35,606 Reputation points Volunteer Moderator
2021-07-30T22:44:19.403+00:00

Two thoughts come to mind

  • Get rid of ~LogIntern() Writing code for an object's finalizer is a complex task that can cause problems if not done correctly
  • Set a breakpoint in the Close method and step through the code.

Was this answer helpful?

1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.