المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Threading Question



C# Programming
06-12-2010, 10:21 AM
Dear Sirs,

I've read google, MSDN and this site quite a bit and can't quite come up with the answer.

I've created a program (server) that is multi-threaded. Here are some descriptions:

Listener thread: This thread sits and listens for TCP connections. When it gets one, it creates a thread for that connection which gets data from that connection and interacts with the database, spawns processes, whatever the client asks for.
Scheduler thread: Certain tasks are scheduled to occur on the server, this thread sits tight and when the appropriate time (specified in config file) comes, it executes the tasks that need to happen one at a time (which then probably connect via the listener).
I would also like a GUI to monitor progress from the clients.

I currently have the following main method:
//[System.STAThread]
public static void Main(string[] args)
{
_con = new DW_DB_Connection();//establishes connection with SQL database in ctor for use by clients.
Start_Threads(); //starts listener and scheduler
//System.Windows.Forms.Application.Run(new UI());
}If I use a GUI, I need STA Thread, right?

My question is this: does STAThreadAttribute diminish the power of my application to multi-thread aggressively (and allow it to scale quite large)?

From what I've read, it might be the case that STA only has an effect when the application uses COM (here (http://msdn.microsoft.com/en-us/library/system.stathreadattribute.aspx)). The scheduler and listener do not...I think, but Windows Forms certainly does. But other sources say it changes the apartment state of the current thread to be single threaded. (http://blogs.msdn.com/b/jfoscoding/archive/2005/04/07/406341.aspx?wa=wsignin1.0)
Let me know what you think.
In Christ,
Aaron Laws

http://ProCure.com