public void Run() { System.Diagnostics.Trace.WriteLine(string.Format("[PID:{2}] {0}.{1}() begin", MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, Thread.CurrentThread.ManagedThreadId)); CurrentIdx = 0; GiftBase gift = null; Reletive fromWhom = null; BuyGift(out gift, out fromWhom); //System.Diagnostics.Trace.WriteLine(string.Format("[PID:{0}] A gift has been bought.", Thread.CurrentThread.ManagedThreadId)); if (null != _ares) { Array.Clear(_ares, 0, _ares.Length); } _ares = _boxes.Select(x => new AutoResetEvent(false)).ToArray(); var _dlgtWhatsInBox = new DefDlgt_WhatsInBox <GiftBase, Reletive>(DlgtFunc_WhatsInBox); _dlgtWhatsInBox.BeginInvoke(gift, _boxes[CurrentIdx], fromWhom, baby, Acb_WhatsInBox, _dlgtWhatsInBox); System.Diagnostics.Trace.WriteLine(string.Format("[PID:{2}] {0}.{1}() See what's in box...", MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, Thread.CurrentThread.ManagedThreadId)); WaitHandle.WaitAll(_ares); System.Diagnostics.Trace.WriteLine(string.Format("[PID:{2}] {0}.{1}() end", MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, Thread.CurrentThread.ManagedThreadId)); }
void Acb_WhatsInBox(IAsyncResult iar) { System.Diagnostics.Trace.WriteLine(string.Format("[PID:{2}] {0}.{1}() begin", MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, Thread.CurrentThread.ManagedThreadId)); if (_boxes.Count > CurrentIdx) { _ares[CurrentIdx].Set(); CurrentIdx++; if (_boxes.Count > CurrentIdx) { GiftBase gift = null; Reletive fromWhom = null; BuyGift(out gift, out fromWhom); var _dlgtWhatsInBox = new DefDlgt_WhatsInBox <GiftBase, Reletive>(DlgtFunc_WhatsInBox); //System.Diagnostics.Trace.WriteLine(string.Format("[PID:{2}] {0}.{1}() gift has been bought", MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, Thread.CurrentThread.ManagedThreadId)); _dlgtWhatsInBox.BeginInvoke(gift, _boxes[CurrentIdx], fromWhom, baby, Acb_WhatsInBox, _dlgtWhatsInBox); //System.Diagnostics.Trace.WriteLine(string.Format("[PID:{2}] {0}.{1}() see what's in box...", MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, Thread.CurrentThread.ManagedThreadId)); } } (iar.AsyncState as DefDlgt_WhatsInBox <GiftBase, Reletive>).EndInvoke(iar); System.Diagnostics.Trace.WriteLine(string.Format("[PID:{2}] {0}.{1}() end", MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, Thread.CurrentThread.ManagedThreadId)); }