Re: Best way to pass var to Threaded Class


ok so I'm working in .Net/C#. I have this CDatabase class for instance. I like to run my CDatabase.Connect() and CDatabase.CreateDataSet() on different threads that way I still have my UI to work with. However those two functions require quite a bit of arguments to start. Such as Connection Strings, IPs, Ports, SQL Statements, Table Names. And when you run a function in a new thread you can't pass it any arguments.

So the question is, whats the best way to get my variables to the new class.. I've been doing just like:

VB Code: CDatabase.ConnectionString = "asdfasdf";CDatabase.IP = "192.168.1.1";CDatabase.Port = 23523;ConnectionThread = new Thread(new ThreadStart(CDatabase.Connect));
is there a better way to encapsulate the variables because doing it this way I have make all those variables PUBLIC which isn't the best of way for encapsulation
Posted On: Saturday 3rd of November 2012 12:47:23 PM Total Views:  191
View Complete with Replies