Thread Safe Events and Static Methods 
Author Message
 Thread Safe Events and Static Methods

If multiple threads are sending in new objects that will raise the
NewObjectEvent, and also calling AppendLog() to add text to the applications
log, what needs to be done to make this thread safe?

public class Global
 {
  public static string Log;

  public delegate void DelegateMyObject(MyObject o);

  public static event DelegateMyObject NewObjectEvent;

  public static void SendNewObject(MyObject o)
  {
   NewObjectEvent(o);
  }

  public static AppendLog(string text)
  {
        this.Log += text + "\n\r";
   }
 }

 public class MyObject
 {
  public MyObject(string text)
  {
   this.Text = text;
  }
  public string Text;
 }

Quote:
}



Thu, 28 Apr 2005 07:16:45 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. Are static methods thread safe?

2. How to make static methods thread safe

3. Call to local static object constructor not thread-safe

4. Why is function static singleton not thread-safe?

5. Is static variable initialization thread-safe?

6. Are events thread safe?

7. Events with static methods

8. Thread safety in static methods

9. ANN: sigslot - C++ Portable, Thread-Safe, Type-Safe Signal/Slot Library

10. Thread and static method call problem

11. Using a non-thread-safe library with threads?

12. Thread functions are thread-safe?

 

 
Powered by phpBB® Forum Software