Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I'm not certain I'm following what you're doing but I'd take a look at an event-based notification system for calling your <code>Notify</code> method from your file access work class. I'm assuming your file access work class is called <code>FileManager</code> and that it's an instance class.</p> <p>First, create a custom <code>EventArg</code> class to store the data you want to relay in the notifications coming out of your <code>FileManager</code> class. Create a <code>DoNotify</code> event in your <code>FileManager</code> class that uses this custom <code>EventArg</code> class and call the event (after populating it with your status data) when you wish to update the <code>Notify</code> method.</p> <p>When you instantiate a <code>FileManager</code> object subscribe to the <code>DoNotify</code> event and in its handler call your <code>Notify</code> method:</p> <pre><code>public class FileManager { public event EventHandler&lt;NotifyEventArgs&gt; DoNotify; private void DoSomethingInterestingMethod() { //... // Let listeners know something interesting happened. var doNotify = DoNotify; if (doNotify != null) { doNotify(this, new NotifyEventArgs(errorLevel, message)); } //... } } public class NotifyEventArgs : EventArgs { public NotifyEventArgs(int errorLevel, string statusMessage) { ErrorLevel = errorLevel; StatusMessage = statusMessage; } public int ErrorLevel { get; private set;} public string StatusMessage { get; private set; } } </code></pre> <p>And then on your BackgroundWorker thread (in <code>DoWork</code>(?)) create one ore more <code>FileManager</code> objects and subscribe to the <code>DoNotify</code> event:</p> <pre><code>var fm = new FileManager(); fm.DoNotify += FileManager_Notify; </code></pre> <p>And in the DoNotify handler call your <code>Notify</code> method:</p> <pre><code>void FileManager_Notify(object sender, NotifyEventArgs e) { Notify(e.ErrorLevel, e.StatusMessage); } </code></pre> <p>I'm not entirely sure of some of your implementation details so I hope I've made myself clear enough to allow you to evaluate this approach and decide if it's right for you.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload