I am adding a background worker process to my dll to report progress back to the gui. I have the following problem
I am getting the following errror :
Severity Code Description Project File Line Suppression State Error CS0120 An object reference is required for the non-static field, method, or property 'Program.slate_ExportReportProgress(object, SlateExportContext.ProgressArgs)' SlateExportApiTest C:\Projects\fhsslateexport\SlateExportApiTest\Program.cs 24 Active
This is my implementation
//update the progress to the client
public EventHandler<ProgressArgs> ReportProgress;
// Eventargs to contain information to send to the subscriber
public class ProgressArgs : EventArgs
{
public int Percentage { get; set; }
public string Message { get; set; }
}
public void TransferToSlateBackground()
{
var worker = new BackgroundWorker();
worker.DoWork += DTOBackGroundWorker;
worker.ProgressChanged += worker_ProgressChanged;
worker.RunWorkerCompleted += WorkDone;
worker.RunWorkerAsync("input");
}
public void DTOBackGroundWorker(object sender, DoWorkEventArgs e)
{
e.Result = e.Argument.Equals("input");
DTOCaseObject();
}
private void worker_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
}
public void WorkDone(object sender, RunWorkerCompletedEventArgs e)
{
var result = (bool)e.Result;
}
The code that raises the ReportProgress
event is:
int step = 100 / CaseAssets.Count();
int i = 0;
// Report progress if somebody is listening (subscribed)
if (ReportProgress != null)
{
ReportProgress(this, new ProgressArgs { Percentage = i, Message = "Exporting to Slate " + caseid.ToString() });
}
But it is when I am calling the code from the gui / console app i have the problem.
here i wire my event handler
_slateExport.ReportProgress += slate_ExportReportProgress;
public void slate_ExportReportProgress(object sender, ProgressArgs e)
{
}
But I am getting the error above
Edit 2
I don't believe this is the main problem the problem I am facing is with an event not a property or a form control