मेरे पास कॉलबैक में कई वेब सेवा कॉल (asychronous) हैं, मैं Excel को परिणाम प्लॉट करूंगा। मैं साजिश विधि सिंक्रनाइज़ करना चाहता हूं। इसलिए मैं निम्नलिखित का उपयोग करता हूं, हालांकि, मैं विजुअल स्टूडियो में ट्रैक करता हूं, हर बार, लॉक (लॉकर) सफल होता है, और कई थ्रेड क्लीयरकॉममेंट चल रहे हैं, प्लॉट। मुझे पता नहीं लगाया जा रहा है कि यह क्यों अपेक्षित काम नहीं कर रहा है! धन्यवादसी # लॉक (mylocker) काम नहीं करता
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);
}
}
यह हो सकता है आप में मदद करता है > http://stackoverflow.com/questions/5053172/why-does-the-lock-object-has-to-be-static – Sadaf