C # блокировка (mylocker) не работает
У меня есть много вызовов веб-службы (асинхронный), в обратном вызове я буду отображать результат в Excel. Я хочу синхронизировать метод сюжета. Поэтому я использую следующее, однако, начиная с отслеживания в Visual Studio, каждый раз, когда блокировка (locker) успешна, и есть много потоков, выполняющих clearcommentIfany, plot. Я не могу понять, почему это не работает, как ожидалось! Спасибо
<code>private readonly object locker = new object(); void ProcessPlot() { lock (locker) { Debug.WriteLine("currentThreadID: " + Thread.CurrentThread.ManagedThreadId); //Helper.Dispatcher.Invoke(new AddClearCommentDelegate(ClearCommentIfAny)); ClearCommentIfAny(); if (Response.status != Status.COMPLETE) { ErrorMessage = ManipulateStatusMsg(Response); //Helper.Dispatcher.Invoke(new AddClearCommentDelegate(AddCommentToCell)); AddCommentToCell(); } else // COMPLETE { // TODO: Convert this into factory pattern Debug.WriteLine("ReportBuilder.Dispatcher's address " + Helper.GetAddress(Helper.Dispatcher)); //Helper.Dispatcher.Invoke(new PlotDelegate(Plot), Response); Plot(Response); } } } public void DataRequestJobFinished(DataRequestResponse response) { try { if (Request.IsRequestCancelled) { Request.FormulaCell.Dispose(); return; } Response = response; //if (response.status != Status.COMPLETE) //{ // ErrorMessage = ManipulateStatusMsg(response); //} //else // COMPLETE //{ // // TODO: Convert this into factory pattern // PlotDelegate plotDelegate = Plot; // Debug.WriteLine("ReportBuilder.Dispatcher's address " + Helper.GetAddress(Helper.Dispatcher)); // Helper.Dispatcher.Invoke(plotDelegate, response); // //Plot(response); //} var t = new Thread(ProcessPlot); t.Start(); //ProcessPlot(); } catch (Exception e) { ErrorMessage = e.Message; MIMICShared.Helper.LogError(e); } finally { //TODO: PutReportBuilderInQueue(this); ReadyForPlot = true; //Request.FormulaCell.Dispose(); move this after plot UnityContainer.Resolve<IEventAggregator>().GetEvent<DataRefreshEvent>().Publish(ID); } } </code>