Homer J. Simpson wrote:
[...]
Now I wanna get rid of the console window. I want this to work as a
windowless program--I don't care if I don't have a UI to shut it down, nor
do I need to present any sort of configuration option. This is a
quick-and-dirty app for myself only.
Personally, I think it's a little goofy to write an application that has
no direct way of telling it to exit. Even if all it has is a single
window with a button named "Exit" or an empty window you can close,
where's the harm in that? Even if it is just something you're going to
use as a one-off tool, why would you want to have to go to the Task
Manager to shut down the application?
That said...I think you want option c:
c) a Windows form application, which I'd then have to modify somehow to get
rid of the default form.
Just edit the Main() method in your Form-based application so that it
doesn't create a form. See Program.cs in your application's project for
the implementation. You may find that you don't even need to call
Application.Run().
And since you didn't ask but I have my opinions anyway:
In your handling of the serial port, IMHO you should do one of the
following:
* Don't use loop calling Sleep()...just call something that will
block indefinitely. For example, create a ManualResetEvent instance,
initialized to unset, and wait on it.
* Even better, don't use the async methods for the SerialPort
class. The only reason they exist is so that your other threads can go
do stuff while the serial port i/o is working. But since you don't have
any other threads, just using blocking i/o calls with the SerialPort
class in your main thread.
These apply whether you're in a console application or a form-less Forms
application.
Pete