That’s my problem really. I can’t articulate what it is I’m trying to do in C#, because I don’t understand the concepts enough. Like, I create a control, then I want to put the methods for that control into a different class, for neatness. But then how the hell do I get to the control (cos it’s private)?
I *think* what I need to do is create a new instance of a class and pass the control to it. Then in the constructor of the new class (sort of, like, the code that’s run when it’s created) I create a copy of the control based on the original. Then from my main code I can call methods in the new class and *somehow* these get applied to my original control.
See, you don’t even understand what I’ve written, that’s because *I* don’t understand what I’ve written either!
I thought this code was handy though – for BackgroundWorker controls. In fact, that *seems* to do what I’m describing. It seems to create some data then pass it to another class which manages to work on it and updates the original data? Pffff
public partial class TaskForm : Form
// RUN ON UI THREAD
void startOperationButton_Click(object sender, EventArgs e)
// Create data to pass to worker thread
MyData data = new MyData();
// Initiate worker thread
// RUN ON WORKER THREAD
void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
// Extract data passed from UI thread
MyData data = (MyData)e.Argument;
// Execute long running, asynchronous operation