title: C# Invisible WCF Host "on demand"
body: <p>I have a 64-bit desktop application that needs to incorporate (32-bit) TWAIN scanner support, so I'm approaching it by writing a 32-bit Self-hosting WCF service. Using a dummy app, I've got my basic approach working, but I'm having a couple difficulties. The 32-bit scanner "app" won't be used outside my calling application, so at the point when the user clicks a "Scan" button in my application, I'm using Process.Start() to fire up the self-hosted scanner app. That part is working fine.</p>
  
  <p>I've currently got the self-hosted scanner app set to a console app. I start it, then call a method defined as Scan() on the WCF service. The Scan() method displays a modal dialog, which allows the user to perform the scan. That's also working fine.</p>
  
  <p>I'm having two problems.</p>
  
  <p>1) The empty console window is also displayed, along with the scan dialog. I don't want to see the console window, so I tried calling Process.Start and specifying ProcessWindowStyle.Hidden. That hid the console window but also had the undesired effect of not allowing the scan dialog to show. I may need to change to a WinForms-based self-hosting scanner app, but then I've got to figure out how to treat it modally (in other words, I want control to be set to the scanner app until the user either clicks Cancel, or scans an image in the scanner app). Any suggestions on the best way to approach this?</p>
  
  <p>2) Once I have a successful scan, I want to "close" the scanner self-hosting application. The only way I've been successful in doing this so far, is to call Process.Kill() from my calling application. I don't like that approach. I tried implementing a CloseHost() method in the WCF service and terminating the host application when that method is called, but then I get a WCF fault because the connection was unexpectedly terminated. I could use suggestions on a good approach to this as well.</p>
  
  <p>Thank you in advance!</p>