I'm experimenting with starting some threads that will run in the background. Eventually, I would like to work up to establishing a database connection on start-up along with having a server thread running that will pass data from some clients into the database. The application will have a GUI with all of the features that the client has (and more)...
BUT, right now, I am stuck on actually starting the thread...It's meant to start as soon as the program starts, but isn't executing until AFTER I hit the exit button on the main form...WHY?
Main Program File:
#region Using Declarations
using ADOX;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.OleDb;
using System.IO;
using System.Linq;
using System.Threading;
using System.Windows.Forms;
#endregion
namespace Trap_App
{
//Main Class
public class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
//Begin Data Handler
DataHandler Database = new DataHandler();
Thread data = new Thread(Database.CreateDB);
data.Start();
}
}
}
Database Handler
#region Using Declarations
using ADOX;
using System;
using System.Data;
using System.Data.OleDb;
using System.IO;
using System.Windows.Forms;
#endregion
namespace Trap_App
{
class DataHandler
{
private const string DB_LOCATION = @".\ATAMaster.accdb";
private OleDbConnection myconnection;
private OleDbCommand command;
private OleDbDataAdapter adapter;
private DataSet dataset;
//Constructor
public DataHandler()
{
}
//Begin Methods
//This method creates an Access 2002-2003 database at DB_LOCATION
//params: in
public void CreateDB()
{
try
{
if (!File.Exists(DB_LOCATION))
{
Catalog cat = new Catalog();
cat.Create("Provider=Microsoft.JET.OLEDB.4.0;" +
"Data Source= " + DB_LOCATION + ";" +
"Jet OLEDB:Engine Type=5");
MessageBox.Show("New Master Database has been created.");
cat = null;
}
}
catch (Exception e)
{
}
}
}
}
Thanks!
EDIT: I feel like I'm completely off base with this code >.>


Sign In
Create Account


Back to top









