c# - Problem with BeginInvoke (the delegate does not perfom any action) -


Hope you're doing well.

I am facing an anxious problem with Begininvoke and I really really need your help

I have a class reporting which types of reports are many examples < / P>

  Class reporting: UserControl {// Report UserControl reports are taken from _report1; Report _report2; Report _report3; // Instanciate and passed ID report (instanciated // instanciated and only if it is created to be empty) report back public report GetReport (int reportId); Public delegate void GenerateReportAsImageDelegate (integer reportId, string path) // report if (InvokeRequired) BeginInvoke (new GenerateReportAsImageDelegate (GenerateReportAsImage), new object [] {generated image saved as public void GenerateReportAsImage (integer reportId, string path) {{ ReportId, path}); } Else {// ... Generate report etc ..}} ....}  

This one user's control is shown in a form and it is the same user control Is also used by Windows

To prepare a report every minute, I am using the system. threading. Timer

Here's my class: Report preparation service looks:

  class ReportServiceClass {Reporting _reportingObject; System.Threading.Timer _timer; Public ReportingServiceClass (integer reportId) {_timer = new Timer (New TimerCallback (this.CreateReport), reportId, 0, 1000)} private void CreateReport (object stateInfo) {int reportId = Convert.ToInt32 (stateInfo); // _reportingObject report to ensure that if (_reportingObject == null) went is created on the same thread as _reportingObject = new _reportingObject (), _reportingObject.GenerateReportAsImage (reportId, @ "c: \ reports \ report.PNG")}  

}

almost everything is working well .. excepet that sometimes executed in another thread CreateReport the ThreadPool so when I report it If I'm taking some action on the components (which are made in other threads), then InvokeRequired is set to true and it is completely clear ... But BeginInvoke does not work anymore! This is almost like thread where the report no longer exists ...

How can you think about how to avoid this problem?

It's been a week now. 'I am facing this problem, I did googol and stackhovarvalv.

I think you used wrong, try this:

  if (this.InvokeRequired) {this.Invoke (new battle of & lt; integer, string & gt; (GenerateReportAsImage), reportId, path); } And ...  

Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -