Click to See Complete Forum and Search --> : I need the best Idea to ...


demian666
March 22nd, 2005, 06:19 AM
Hi all,
I want to make a .dll that has inside one static class
named "ErrorHandler" with just one static method inside
named "WhileLogLine" with one parameter, the text to be log in.
I want it to works like the Console.writeline, but intead of printing
in Console, I want to write in a log file.

How can I make this to avoid this possible problems:

1.- File Locks
2.- File write process to large in time ( I want to call static method and not to wait until log write was made)

Thanks a lot for your ideas and sorry about my poor english

Krzemo
March 22nd, 2005, 06:54 AM
One possible way is to make a queue and add messages to that queue while another thread will empty queue and write messages to the log file.

1.- File Locks
What do U mean by that?
Please explain.

Best regards,
Krzemo.

demian666
March 22nd, 2005, 07:13 AM
The queu idea is a good idea, but think it's a static class in a dll, you can't make an "eternal thread".
The File lock idea its more or less this:
If I use this .dll from several modules, perhaps all of them try to open the same log file at the same time, then an error ocurrs, but i want the method to wait for the other module to unlock the file and then write on this....but I don't want the static method caller to wait until this ocurrs....
I don't know if I explain this well....

Krzemo
March 22nd, 2005, 07:39 AM
you can't make an "eternal thread". No, U can create 1 worker thread for each process which will use that dll.

By default, each process using a DLL has its own instance of all the DLLs global and static variables (if not using data_seg pragma). So it is pretty safe to use them.

For file locking: Each process can try to open file for appending (and if not opened -then wait), than write 1 message,flush and close the file, do Sleep(0) to give other threads a chanse to work,.... until queue is empty (than wait for new messages).

Best regards,
Krzemo.