// Copyright (c) CypherCore All rights reserved. // Licensed under the GNU GENERAL PUBLIC LICENSE. See LICENSE file in the project root for full license information. using Framework.Threading; using System.Threading; namespace Framework.Database { public interface ISqlOperation { bool Execute(MySqlBase mySqlBase); } class DatabaseWorker { Thread _workerThread; volatile bool _cancelationToken; ProducerConsumerQueue _queue; MySqlBase _mySqlBase; public DatabaseWorker(ProducerConsumerQueue newQueue, MySqlBase mySqlBase) { _queue = newQueue; _mySqlBase = mySqlBase; _cancelationToken = false; _workerThread = new Thread(WorkerThread); _workerThread.Start(); } void WorkerThread() { if (_queue == null) return; for (; ; ) { ISqlOperation operation; _queue.WaitAndPop(out operation); if (_cancelationToken || operation == null) return; operation.Execute(_mySqlBase); } } } }