Click here to Skip to main content
15,892,746 members
Home / Discussions / C#
   

C#

 
GeneralRe: thread safe log class with simple functionality Pin
Richard Deeming22-Oct-15 7:18
mveRichard Deeming22-Oct-15 7:18 
GeneralRe: thread safe log class with simple functionality Pin
Member 1206160022-Oct-15 10:36
Member 1206160022-Oct-15 10:36 
GeneralRe: thread safe log class with simple functionality Pin
Member 1206160022-Oct-15 6:35
Member 1206160022-Oct-15 6:35 
GeneralRe: thread safe log class with simple functionality Pin
Richard Deeming22-Oct-15 6:54
mveRichard Deeming22-Oct-15 6:54 
GeneralRe: thread safe log class with simple functionality Pin
Richard Deeming22-Oct-15 2:39
mveRichard Deeming22-Oct-15 2:39 
GeneralRe: thread safe log class with simple functionality Pin
Member 1206160022-Oct-15 5:34
Member 1206160022-Oct-15 5:34 
GeneralRe: thread safe log class with simple functionality Pin
Richard Deeming22-Oct-15 5:37
mveRichard Deeming22-Oct-15 5:37 
AnswerRe: thread safe log class with simple functionality Pin
John Torjo21-Oct-15 23:08
professionalJohn Torjo21-Oct-15 23:08 
First off, I would use a dedicated thread to do the logging. But just in case you don't want that, you should not lock while in the process of saving

C#
List<string> copy = null;
lock(_syncObject) {
  _buffer.Add(logMessage);
  if ( _buffer.Count > _maxBufferSize) {
    copy = _buffer;
    _buffer = new List<string>();
  }
}
if ( copy != null) 
  Save(copy);


(you would need to adjust your Save() function as well.

LATER EDIT: you will probably need a second lock for saving, but the main idea is that other threads would not be blocked when the buffer gets full.

Best,
John
-- LogWizard - Log Viewing can be a joy!

QuestionTabelLayoutPanel Resizing at Runtime c#.net Pin
Darshan BS20-Oct-15 21:47
Darshan BS20-Oct-15 21:47 
AnswerRe: TabelLayoutPanel Resizing at Runtime c#.net Pin
OriginalGriff20-Oct-15 22:31
mveOriginalGriff20-Oct-15 22:31 
GeneralRe: TabelLayoutPanel Resizing at Runtime c#.net Pin
Darshan BS20-Oct-15 22:41
Darshan BS20-Oct-15 22:41 
GeneralRe: TabelLayoutPanel Resizing at Runtime c#.net Pin
OriginalGriff20-Oct-15 22:50
mveOriginalGriff20-Oct-15 22:50 
AnswerRe: TabelLayoutPanel Resizing at Runtime c#.net Pin
BillWoodruff21-Oct-15 2:01
professionalBillWoodruff21-Oct-15 2:01 
Questionneed help. No error in code but not getting output. here is my code. trying to accessing data from active directory. Pin
rahul38420-Oct-15 17:31
rahul38420-Oct-15 17:31 
AnswerRe: need help. No error in code but not getting output. here is my code. trying to accessing data from active directory. Pin
Richard MacCutchan20-Oct-15 21:38
mveRichard MacCutchan20-Oct-15 21:38 
AnswerRe: need help. No error in code but not getting output. here is my code. trying to accessing data from active directory. Pin
Richard Deeming21-Oct-15 1:48
mveRichard Deeming21-Oct-15 1:48 
QuestionWindows Remote Application is not working Pin
Josephss7318-Oct-15 22:35
Josephss7318-Oct-15 22:35 
QuestionHow should I access share folder from server Pin
Member 1201610618-Oct-15 21:10
Member 1201610618-Oct-15 21:10 
AnswerRe: How should I access share folder from server Pin
OriginalGriff18-Oct-15 23:12
mveOriginalGriff18-Oct-15 23:12 
Question[WIN2D] Randomly generated 2D drawing Pin
Member 858597418-Oct-15 14:10
Member 858597418-Oct-15 14:10 
Questionc# delegates and events Pin
Lillepige17-Oct-15 6:06
Lillepige17-Oct-15 6:06 
AnswerRe: c# delegates and events Pin
BillWoodruff17-Oct-15 6:25
professionalBillWoodruff17-Oct-15 6:25 
QuestionImplement my own IFormatProvider class Pin
Member 905073117-Oct-15 5:29
Member 905073117-Oct-15 5:29 
SuggestionRe: Eigene IFormatProvider implemetieren Pin
Jochen Arndt17-Oct-15 6:14
professionalJochen Arndt17-Oct-15 6:14 
AnswerRe: Eigene IFormatProvider implemetieren Pin
Dave Kreskowiak17-Oct-15 6:29
mveDave Kreskowiak17-Oct-15 6:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.