Reputation: 387
my backgroundworker should return the percentage and also an object. Its a struct.
serialPort.DiscardInBuffer(); // clear InBuffer
serialPort.Write(adv_request, 0, 3); // Write byte array to serial port, with no offset, all 3 bytes
process_DoWork(serialPort);
worker.ReportProgress(0, pfc_parsedData); //return parsed data to main thread
Here I get an exception "System.InvalidCastException"
public void request_ProgressChanged(object sender, ProgressChangedEventArgs e) //this function is need update mainthread controls
{
if (e.ProgressPercentage == 0)
{
sbStatus.Text = "Logging active...";
Pfc_parsedData pfc_parsedData = (Pfc_parsedData)sender;
}
else
{
sbStatus.Text = "Offline";
}
}
Upvotes: 0
Views: 263
Reputation: 203823
The sender
is the background worker, not the data that you provided when reporting progress. That data is in e.UserState
.
Upvotes: 2