I have a ThreadStatic variable declared in my main form as such:
[ThreadStatic]
public bool _skipCurrent = false;
I have execute another function and feed data back to my main form using the following code:
var updateMe = new Progress<RunProgressModel>(progress =>
{
// This works
lblTest.Text = progress.Message;
});
await Task.Run(() => monitor.Start(updateMe));
"monitor.Start" is in another class within another project and looks like this:
public void Start(IProgress<RunProgressModel> progress)
{
var currentIndex = 0;
var updateData = new RunProgressModel();
foreach (var task in tasks)
{
bool done = false;
while (!done)
{
// Perform tasks
updateData.Message = "I did a thing.";
}
progress.Report(updateData);
}
}
I need to access the _skipCurrent from inside that thread, to see if the task needs to finish processing that task earlier than it normally would, how do I get this Start function to see the ThreadStatic variable?
I essentially want the user to be able to click a "Skip" button that would set _skipCurrent to true, the thread to skip its current task, and then set the variable back to false.