title: File Dialog from a Background Worker
body: <p>While maintaining some code, I discovered that we have an infinite hang-up in a <strong>background worker</strong>. The worker requires access to a script file. The original code was written to pop up a file dialog if no script file was defined, to allow the user to select one. It looks something like this:</p>
  
  <pre><code>private void bgworker_DoWork(object sender, DoWorkEventArgs e)
  {
      ... snip ...
  
      if (String.IsNullOrWhitespace(scriptFile))
      {
           scriptFile = PromptForScript();
      }
  
      ... snip ...
  }
  
  private string PrompForScript()
  {
      string script = "";
      OpenFileDialog openDialog = new OpenFileDialog();
  
      if (openDialog.ShowDialog() == DialogResult.OK)
      {
          script = openDialog.FileName;
      }
  
      return script;
  }
  </code></pre>
  
  <p>I've read up a bit about <code>MethodInvoker</code>, but almost all of the invoke methods require that you call them from a control. The background worker in question is <strong>running from a separate class, which doesn't extend <code>Control</code></strong>. Do I use the form that calls the class with the bgworker for that? Or is there another way of interrupting the thread for user input?</p>