forum

Home / DeveloperSection / Forums / C# .net event handler delegate question

C# .net event handler delegate question

Dag Hammarskjold 2392 10-Aug-2013
Class A includes a variable A to hold the status of an event that is triggered in Class C ( doEvent() ). The thread sleeps for 500 ms as it waits for Class B to kick off an Event which send the EventArg data back to Class C and calls an Event Handler UpdateClassVar(EventArgs e) - which is what it waits for.

Question: How do I used Event Handler to trigger next step in Class C ( // do something ) that is dependent on Status Update without relying on a Thread.Sleep... ??

Disclaimer: Consider me a novice programmer. Consider this my best attempt and a fairly non-elegant solution. Please feel free to re-design and re-code, this should be considered as only one prototype effort to solve above issue.

NOTE: Code Exampled Edited for 'real - world' example that should actually work. ( not fully tested )

Additional Question - Thread.Sleep(400) in example below stops main thread... halting all processes, although looking for an alternative, is this even a viable solution??

 public class OrderA :
ICurrencyOrder
 {
     private int _clid;
     private string _status;
     public int Clid
     {
         get { return _clid; }
         set { _clid = value; }
     }
     public string Status
     {
         get { return _status; }
         set { _status = value; }
     }
 }
 Class B
 {
      // event delegate for UpdateOrder
      public event UpdateOrderDelegate UpdateOrderEvent;
      /* Code Here to receive and process order assign status etc */
      /* An Event Arguments (args)  Class is created that hold e.Status and e.Clid values */


c# c# 
Updated on 10-Aug-2013

Can you answer this question?


Answer

1 Answers

Liked By